Skip to content

Instantly share code, notes, and snippets.

@cseder
Last active December 19, 2015 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cseder/6031249 to your computer and use it in GitHub Desktop.
Save cseder/6031249 to your computer and use it in GitHub Desktop.
Looping through the chars in a std::string an converting them to uppercase "in-place" (same memory address). Using C++11 features.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s("chris sederqvist");
if (s.begin() != s.end())
{
for(auto &t : s)
{
auto *tp = &t;
*tp = toupper(*tp);
}
}
cout << s << endl;
}
@cseder
Copy link
Author

cseder commented Jul 18, 2013

Just to show off some C++11 syntax.
I really like C++11's range for and iterators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment