Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
char s1[1024], s2[1024];
cin.get(s1, 1024);
cin.get();
cin.get(s2, 1024);


When I input s1 an empty string by press Enter, the program ends immediately and I have no chance to input s2. Why??? I think cin.get() has already eaten the Enter character '\n'.
Posted

1 solution

You need to clear the error state from the first cin.get() call, as it has not received any valid input. Check the <istream>[^] reference on MSDN.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900