• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

stupid c++ question

cliftonite

Diamond Member
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.
 
The '\n' is a combination character intended for output. (Carriage Return & Line Feed)
It may not be the character returned when the Enter key is pressed.
 
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.
 
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?
 
Back
Top