Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created July 8, 2014 06:44
Show Gist options
  • Save elleryq/261bdaab58b30c9cc0e7 to your computer and use it in GitHub Desktop.
Save elleryq/261bdaab58b30c9cc0e7 to your computer and use it in GitHub Desktop.
Split string according to space and convert each token to uppercase.
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
std::string toupper(std::string& s) {
for(std::string::iterator c=s.begin(); c!=s.end(); c++) {
*c = std::toupper(*c);
}
return s;
}
int main(int argc, char* argv[]) {
std::string s = "Innovation links to the future";
std::string token;
std::istringstream is(s);
while(is >> token) {
std::cout << "token: " << toupper(token) << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment