instr2.cpp 490 B

123456789101112131415161718
  1. // instr2.cpp -- reading more than one word with getline
  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.getline(name, ArSize); // reads through newline
  11. cout << "Enter your favorite dessert:\n";
  12. cin.getline(dessert, ArSize);
  13. cout << "I have some delicious " << dessert;
  14. cout << " for you, " << name << ".\n";
  15. // cin.get();
  16. return 0;
  17. }