Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > cin.seekg(ios::end);

Reply
Thread Tools

cin.seekg(ios::end);

 
 
redbox
Guest
Posts: n/a
 
      03-30-2007
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 !

 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      03-30-2007

redbox <(E-Mail Removed)> wrote in message ...
> 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++;


Instead of 'seekg(end)', use 'cin.ignore(<somebigvalue>);'.

> who can tell me why ?
> thank you !


FAQ: http://www.parashift.com/c++-faq-lite/

--
Bob R
POVrookie


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments