Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created May 18, 2015 22:57
Show Gist options
  • Save krysseltillada/88c9a4159ee47e589a70 to your computer and use it in GitHub Desktop.
Save krysseltillada/88c9a4159ee47e589a70 to your computer and use it in GitHub Desktop.
uppercasing each words(each strings) in a vector
#include <iostream> /// std::cout // std::endl
#include <vector> /// std::vector
#include <cctype> /// toupper();
int main()
{
std::vector<std::string> words; /// initialized a empty vector of string
std::string temp_word; /// stores an temporary input
while(std::cin >> temp_word)
words.push_back(temp_word); /// pushes to word element
for(auto &w : words) { /// for every w in words /// deduces or assumes that w is a reference string that is bound to words
for(auto &c : w) { /// for every c in w /// deduces or assumes that c is a reference char that is bound to w
c = toupper(c); /// converts every reference char to uppercase
}
}
for(auto w_upper : words) /// for every w_upper in words /// deduces or assumes that w_upper is a string
std::cout << w_upper << std::endl; /// displays the value
return 0; /// successfull exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment