User input... How to check for ENTER key
Posted
by user69514
on Stack Overflow
See other posts from Stack Overflow
or by user69514
Published on 2010-04-22T04:38:37Z
Indexed on
2010/04/22
4:43 UTC
Read the original article
Hit count: 726
I have a section of code where the user enters input from the keyboard. I want to do something when ENTER is pressed. I am checking for '\n' but it's not working. How do you check if the user pressed the ENTER key?
if( shuffle == false ){
int i=0;
string line;
while( i<20){
cout << "Playing: ";
songs[i]->printSong();
cout << "Press ENTER to stop or play next song: ";
getline(cin, line);
if( line.compare("\n") == 0 ){
i++;
}
}
}
© Stack Overflow or respective owner