//-------------------------------------------------------------------- // // Example showing the getline() function getline.cpp // //-------------------------------------------------------------------- #include // For cin and cout void main() { char str[11]; // Input string int num; // Input number // Read and output a string that includes spaces. cout << endl << "Enter the string \"show me\" (no quotes): "; cin.getline(str,11,'\n'); cout << "String input: " << str << endl << endl; // Read a number followed by a string that includes spaces. cout << endl << "Enter \"10 show me\" (no quotes): "; cin >> num; cin.getline(str,11,'\n'); cout << "Number: " << num << endl; cout << "String: " << str << endl; // Use the get() function to remove the space between the // number 10 and the string "show me". cout << endl << "Enter \"10 show me\" (no quotes): "; cin >> num; cin.get(); cin.getline(str,11,'\n'); cout << "Number: " << num << endl; cout << "String: " << str << endl << endl; }