Last active
December 19, 2015 22:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just to show off some C++11 syntax.
I really like C++11's range for and iterators.