Press the 'enter' key to move forward

372 views Asked by At

I would like my program to only move forward when the enter key is pressed (not any other key).

This is what I have so far:

while (getline(in, line) )   {

                cout << line << endl;;

                cin.ignore();
}
1

There are 1 answers

1
Tony Delroy On BEST ANSWER

ignore accepts a delimiter argument:

basic_istream& ignore( std::streamsize count = 1, int_type delim = Traits::eof() );

You can use it like this:

cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');