
please wait
std::cin >> i ; // type in "1234 abcd" ;
<space>abcd<newline>
remains in the input buffer. std::getline( std::cin.ignore(), myString ) ;
std::cin.ignore()
extracts and discards once character (space) from the input bufferabcd<newline>
remains in the input buffer. std::getline()
extracts abcd<newline>
, places abcd
into myString, throws away the newline and returns immediately. std::getline( std::cin.ignore( 100, '\n' ), myString ) ;
std::cin.ignore( 100, '\n' )
extracts and discards everything in the input buffer (up to a maximum of 100 characters or till a newline is encountered).std::getline()
sees that the buffer is empty and waits for user input.