473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

cin.seekg(ios::end);

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 !

Mar 30 '07 #1
1 3836

redbox <gu********@gmail.comwrote 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
Mar 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Siemel Naran | last post by:
How to compare if two files are identical? I wrote the following: bool comparefiles(const std::string& lhs, const std::string& rhs) { std::ifstream lhsfile(lhs.c_str()); std::ifstream...
4
by: James Aguilar | last post by:
Hey all, I'm working on an encoding scheme where I am running into a problem with reading a file off a stream. Looking at the binary encoding of the file (using a simple hex editor), there is...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
8
by: dbuser | last post by:
Hi, I need help on a problem, as described below. I am reading a file "input.txt"which has data like this: abc def gh izk lmnopq rst uvwxyz I am using fstream object to read the file and...
2
by: Assertor | last post by:
Hi, All. (VC++6.0) I found some strange thins when using getline() and seekg() of std::ifstream. After the file position of an open file was shift to the end of the file, seekg() did not...
1
by: pantatkau | last post by:
i am trying to use the seekg(offset, base) function to move the read position but cant seem to do it correctly. When i use tellg() to know if the seekg operation is successful or not , the tellg()...
12
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works...
5
by: Angus | last post by:
Hello I am using ifstream to load the contents of a text file into a char* variable. I am allocating using new with the file size as amount to allocate. My problem is that the variable...
1
by: vsachar | last post by:
I had a doubt about the end of file. I read the entire file and reached the end of file after which I'm not able to get the file pointer back to the start of file. I tried seekg() and it didn't...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.