41 lines
957 B
C++
41 lines
957 B
C++
|
// 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;
|
||
|
}
|