hello all
i dont know what is the problem ....... a very simple change in the order of functions make the program goes in infinite loop
this code works will
#include <iostream>
using namespace std;
int main()
{
int i;
while(true)
{
cout << "\nEnter Intger:";
cin >> i;
if (cin.good())
{
break;
cin.sync();
}
cin.clear();
cin.sync();
cout << "\nError\n";
}
cout << "\nYou Entered :"<<i;
return 0;
}
but when i swap cin.sync and cin.clear
like that
#include <iostream>
using namespace std;
int main()
{
int i;
while(true)
{
cout << "\nEnter Intger:";
cin >> i;
if (cin.good())
{
break;
cin.sync();
}
cin.sync();
cin.clear();
cout << "\nError\n";
}
cout << "\nYou Entered :"<<i;
return 0;
}
infinite loop happens
why ?? and please if any one has a link that takes about buffer please give it to me