1
0

get_fun.cpp 917 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // get_fun.cpp -- using get() and getline()
  2. #include <iostream>
  3. const int Limit = 255;
  4. int main()
  5. {
  6. using std::cout;
  7. using std::cin;
  8. using std::endl;
  9. char input[Limit];
  10. cout << "Enter a string for getline() processing:\n";
  11. cin.getline(input, Limit, '#');
  12. cout << "Here is your input:\n";
  13. cout << input << "\nDone with phase 1\n";
  14. char ch;
  15. cin.get(ch);
  16. cout << "The next input character is " << ch << endl;
  17. if (ch != '\n')
  18. cin.ignore(Limit, '\n'); // discard rest of line
  19. cout << "Enter a string for get() processing:\n";
  20. cin.get(input, Limit, '#');
  21. cout << "Here is your input:\n";
  22. cout << input << "\nDone with phase 2\n";
  23. cin.get(ch);
  24. cout << "The next input character is " << ch << endl;
  25. /* keeping output window open */
  26. /*
  27. cin.clear();
  28. while (cin.get() != '\n')
  29. continue;
  30. cin.get();
  31. */
  32. return 0;
  33. }