I am new to C++ and I like Devc++, but I am tired of everytime, in my programs, I ask for input from the keyboard with getch() the next time I ask for input with 'cin >>', I have to backspace to delete the input from the getch(). Anyone have a solution?
I have tried 'fflush(stdin)' it doesn't work.
HELPPPPPPP!!!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am new to C++ and I like Devc++, but I am tired of everytime, in my programs, I ask for input from the keyboard with getch() the next time I ask for input with 'cin >>', I have to backspace to delete the input from the getch(). Anyone have a solution?
I have tried 'fflush(stdin)' it doesn't work.
HELPPPPPPP!!!!!
Put this before your cin
cin.ignore(100, '\n');
Curtis
here is a simple example:
#include<iostream>
#include<conio.h>
int main()
{
char a,b;
cout << "input a letter: ";
a=getch();
cout << "\ninput another letter: ";
cin.ignore(100, '\n');
cin >> b;
cout << "a= " << a << " b= " << b;
getch();
return 0;
}
I don't want to print the character from the getch()
at the next cin. I tried your suggestion, it does ignore it but it still prints it there
Curtis thanks for your help.
I figured it out I think.
I added:
int k=getch();//a dummy input
to catch the last key stroke.
it seemed to work for my program.
thanks again.