/* testio0.cpp CIS 150 May 2008 David Klick This program demonstrates a few cin input functions and the use of C-style strings. */ #include using std::cout; using std::cin; void cont(); int main() { // declare variables int n, n2; char ch; char line[50]; cout << "Enter a character: "; cin >> ch; cout << ch << '\n'; cin.ignore(); // skips "Enter" from last user input cout << "Enter a character: "; cin.get(ch); cout << ch << '\n'; // This technique will not work if input has spaces cout << "Enter your name (no spaces allowed): "; cin >> line; cout << line; // This technique reads a whole line including spaces cin.ignore(); cout << "Enter your name (spaces allowed): "; cin.getline(line, 50); cout << line; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }