instr3.cpp 501 B

123456789101112131415161718
  1. // instr3.cpp -- reading more than one word with get() & get()
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. const int ArSize = 20;
  7. char name[ArSize];
  8. char dessert[ArSize];
  9. cout << "Enter your name:\n";
  10. cin.get(name, ArSize).get(); // read string, newline
  11. cout << "Enter your favorite dessert:\n";
  12. cin.get(dessert, ArSize).get();
  13. cout << "I have some delicious " << dessert;
  14. cout << " for you, " << name << ".\n";
  15. // cin.get();
  16. return 0;
  17. }