PracticeDev/study_cpp/cpp_primer_source_code/Chapter 17/get_fun.cpp

41 lines
957 B
C++
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
// get_fun.cpp -- using get() and getline()
#include <iostream>
const int Limit = 255;
int main()
{
using std::cout;
using std::cin;
using std::endl;
char input[Limit];
cout << "Enter a string for getline() processing:\n";
cin.getline(input, Limit, '#');
cout << "Here is your input:\n";
cout << input << "\nDone with phase 1\n";
char ch;
cin.get(ch);
cout << "The next input character is " << ch << endl;
if (ch != '\n')
cin.ignore(Limit, '\n'); // discard rest of line
cout << "Enter a string for get() processing:\n";
cin.get(input, Limit, '#');
cout << "Here is your input:\n";
cout << input << "\nDone with phase 2\n";
cin.get(ch);
cout << "The next input character is " << ch << endl;
/* keeping output window open */
/*
cin.clear();
while (cin.get() != '\n')
continue;
cin.get();
*/
return 0;
}