////////////////////////////////////////////////////////////////////// // // cppstrings.cpp // // Started by Jeff Ondich on 4/1/98 // Last modified 1/7/00 // // This program demonstrates the C++ "string" // variable type. // // 1. Note that to use the string type, you need to // #include . // // 2. Compile and run the program. // // 3. What's the \" about in the output statements? // // 4. What if you type a return or two between your first // and second words? What if you have punctuation // between them? // // 5. What does thisWord[i] mean? What values of // i make sense in this context. // ////////////////////////////////////////////////////////////////////// #include #include int main( void ) { string thisWord, thatWord; // Get input from the user. cout << "Type a sentence, please: "; cin >> thisWord >> thatWord; // Report some obvious stuff to the user. cout << "The first word you typed was \"" << thisWord << "\"" << endl; cout << "The second was \"" << thatWord << "\"" << endl; cout << "\"" << thisWord << "\" is " << thisWord.length() << " characters long." << endl; // Change the first word to all upper case. int length = thisWord.length(); for( int i=0; i < length; i++ ) thisWord[i] = toupper( thisWord[i] ); cout << "Here's your first word, upper case: " << thisWord << endl; return( 0 ); }