Skip to content

Instantly share code, notes, and snippets.

@mahata
Created September 28, 2011 20:15
Show Gist options
  • Save mahata/1249132 to your computer and use it in GitHub Desktop.
Save mahata/1249132 to your computer and use it in GitHub Desktop.
C++ Primer 8.3
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void capitalize_all(string & text);
int main()
{
string text;
cout << "Enter a string (q to quit): ";
getline(cin, text);
if ("q" == text) {
cout << "Bye." << endl;
return 0;
}
capitalize_all(text);
cout << text << endl;
while (true) {
cout << "Next string (q to quit): ";
getline(cin, text);
if ("q" == text) {
cout << "Bye." << endl;
return 0;
}
capitalize_all(text);
cout << text << endl;
}
return 0;
}
void capitalize_all(string & text)
{
for (int i = 0; i < text.size(); i++) {
text[i] = toupper(text[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment