Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using m menu function in c++ console app. it selects on pressing enter key but it i call it back to back then it select first option automatically. how can i clear input buffer so that '\n' is ignored.
for example i have 2 menus
<----main menu----->
Create
Display
Delete
Exit

<---- create SubMenu----->
Manager
Labour
Back


in this menus, if i select create option then manager is selected atomatically.

What I have tried:

i tried
<pre lang="c++">
cin.ignore();
cin.ignore(/*length*/,'\n');
cin.ignore('\0');
cin.sync();

but nothing worked.
Posted
Updated 16-Dec-17 6:44am

1 solution

 
Share this answer
 
v3
Comments
Arham Anees 16-Dec-17 21:01pm    
no such function. cin.readsome() do you mean?
Richard MacCutchan 17-Dec-17 3:21am    
Sorry, should be getline(). Too many different languages in my head.

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