stupid c++ question

cliftonite

Diamond Member
Jul 15, 2001
6,900
63
91
Lets say a user enters in a bunch of characters like ab12ab12 and then hits enter. How do i check for the enter keystroke in a loop? I tried while ( cin.get() !='\n' ) but that is not doing it (it does not go on to the next operation.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
The '\n' is a combination character intended for output. (Carriage Return &amp; Line Feed)
It may not be the character returned when the Enter key is pressed.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
What are you trying to do? If you're just trying to read a line of text from the user, there are easier ways than a loop that runs once for every key stroke.
 

EmperorRob

Senior member
Mar 12, 2001
968
0
0
If you just want to trap all chars up to the enter use cin.getline(). Or is this some kind of menu-driven keystroke loop?