Originally Posted by
mrafcho001
im not a cin.get() fan but i think you have to clear the stream:
Code:
cin.get();
cin.ignore();
Those are backward. You clear the newline from the stream first, then use cin.get() to do a blocking read. That's assuming, of course, that the next character on the stream is a newline.
Originally Posted by
mrafcho001
or this:
Code:
//replace those two with this:
system("PAUSE");
This is not a better option. cin.get() is the best portable option as long as you make sure to clear the stream state and discard any extraneous characters:
Code:
#include <iostream>
#include <limits>
#include <string>
using namespace std;
void clear_stream ( istream& in )
{
in.clear();
in.ignore ( numeric_limits<streamsize>::max(), '\n' );
}
int main()
{
string Matt;
cout << "Please enter something for me to say: ";
getline ( cin, Matt );
cout << "\n" << "Matt says: ";
cout << Matt;
// Clear first, then read
clear_stream ( cin );
cin.get();
return 0;
}