473,406 Members | 2,390 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,406 software developers and data experts.

ifstream in text mode + seekg problem

Hi,

// Under C++Builder 2007 (+ Dinkumware)
#include <fstream>
using namespace std;

int main (int argc, char* argv[])
{
// Create a DOS-Text file, that has only two lines:
// - the first line is empty ("\r\n"),
// - the second line: "ABC".
// Then:

ifstream is ("c:\\abc.txt");

while (is.peek() != 'A') // It's a dead loop here... Why?
is.seekg (1, ios::cur);

return 0;
}

Thanks,
Vadim
Jan 18 '08 #1
1 4453
Vadim Volevach wrote:
// Under C++Builder 2007 (+ Dinkumware)
#include <fstream>
using namespace std;
int main (int argc, char* argv[])
{
// Create a DOS-Text file, that has only two lines:
// - the first line is empty ("\r\n"),
// - the second line: "ABC".
// Then:
ifstream is ("c:\\abc.txt");
while (is.peek() != 'A') // It's a dead loop here... Why?
is.seekg (1, ios::cur);
return 0;
}
It's undefined behavior. The only seeking you can do in a text
file is to the start of the file, to the current position, or to
a streampos returned from a call to tell[gp]().

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 18 '08 #2

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

Similar topics

1
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
7
by: Hamburgpear | last post by:
Dear All, Is it possible to reset the value of xxx.peek() after it reachs EOF ? Regards HP
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...
2
by: Karl | last post by:
Hey everyone! I've got a quick question on whether std::ifstream is buffered or not. The reason is that I have a homework assignment that requires me to benchmark copying files using different...
5
by: Kamran | last post by:
Hi, I am having problem using std::ifstream in my code under solaris. Everything works fine on linux but the same thing i.e. trying to read a binary file and fill in a struct result in complete...
3
by: toton | last post by:
Hi, I want to unread a few things while I am reading a file. One solution I know is putback the characters read to the buffer. But as I need frequent moving file pointer , to a few steps back, I...
4
by: supemoy | last post by:
I am having a heck of a time using the ifstream::read() method. I am using Visual Studio 6.0, and my intelisense indicates that read has an overload of: ifstream::read(unsigned char*, int _n) A...
2
by: Angus | last post by:
Hello Here is my code std::ifstream myfile; std::string line; long begin,end;
1
by: Sergei Shelukhin | last post by:
Hi. I have the following problem; VC++ project, there's this code operation on 500Mb file via ifstream, POS_TYPE for this case is unsigned int which is 32-bit long. //dataFile.good() returns 1...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.