//-------------------------------------------------------------------- // // Example showing character I/O chario.cpp // //-------------------------------------------------------------------- #include // For cin and cout void main() { char ch, // Input character str[11]; // Input string int num; // Input number // Read and output a character. cout << "Enter a character: "; cin >> ch; cout << "Character input: '" << ch << "'" << endl; // Read and output a string. cout << endl << "Enter the string \"show\" (no quotes): "; cin >> str; cout << "String input: " << str << endl; // Read a number followed by a string. cout << endl << "Enter \"10 show\" (no quotes): "; cin >> num >> str; cout << "Number: " << num << endl; cout << "String: " << str << endl; // Read a string followed by a number. cout << endl << "Enter \"show 10\" (no quotes): "; cin >> str >> num; cout << "String: " << str << endl; cout << "Number: " << num << endl; // PROBLEM: What if a string includes spaces? // Read and output a string that includes spaces. cout << endl << "Enter the string \"show me\" (no quotes): "; cin >> str; cout << "String input: " << str << endl << endl; // SOLUTION: Need to use the getline() function to read in // a string that includes spaces. See the file getline.cpp }