R
redbox
i want some code to get a int from user;
code as show follow:
#include <iostream>
using namespace std;
int main()
{
int c;
cin>>c;
while(cin.fail())
{
cout<<"Need a int,try again!"<<endl;
cin.clear();
cin.seekg(ios::end);
cin>>c;
}
}
but it work well in vc6 and ibm xlC,buf failed in g++;
who can tell me why ?
thank you !
code as show follow:
#include <iostream>
using namespace std;
int main()
{
int c;
cin>>c;
while(cin.fail())
{
cout<<"Need a int,try again!"<<endl;
cin.clear();
cin.seekg(ios::end);
cin>>c;
}
}
but it work well in vc6 and ibm xlC,buf failed in g++;
who can tell me why ?
thank you !