elleryq
7/8/2014 - 6:44 AM

Split string according to space and convert each token to uppercase.

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;
}