#include #include "CPstring.h" // file: capital.cc // author Dietolf Ramm; date: 11/12/96 // Capitalize words in a line // Illustrate vector of character property of strings void Capitalize(string & title) // precondition: assumes title has not leading nor trailing blanks // and exactly one blank between each word // postcondition: first letter of each word is capitalized { int k; if (title.length() == 0) return; title[0] = toupper(title[0]); for (k = 0; k < title.length(); k++) { if (title[k] == ' ') { title[k+1] = toupper(title[k+1]); } } } int main() { string line; cout << "Enter a title with one blank between each word." << endl; getline(cin, line); while (line.length() > 0) { Capitalize(line); cout << line << endl; cout << "Enter a title with one blank between each word." << endl; getline(cin, line); } return 0; } Sample output: capital Enter a title with one blank between each word. testing one two three Testing One Two Three Enter a title with one blank between each word. WHOs afraid of Virginia Wolf? WHOs Afraid Of Virginia Wolf? Enter a title with one blank between each word. aaa bbb cccc Aaa Bbb Cccc Enter a title with one blank between each word.