#include <iostream>
#include <istream>
using namespace std;
int main()
{
char a = '\0';
char b = '\0';
cin.get(a);
cout << a <<endl;
cin.sync();
cin.get(b);
cout << b <<endl;
return 0;
}
input:
sssssssssssssssss\n
result:
s
s
The correct result I expect is I can type twice,even though I type many characters the first time! like this:
input:
ssssssssssssssss\n
the first cout:
s
wait my second typing:
wwwwwwwwwwwww\n
the second cout:
w
I want to use cin.sync()
to clear input buffers, but why it does not work?