473,387 Members | 1,890 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,387 software developers and data experts.

don't sync() on an fstream at EOF

I open an fstream in read-only mode, read till the end, then try to
sync() before seeking to position 0 & reading again. But the sync
fails. I discovered that clear()ing the stream before the sync causes
the sync to work. Seeking to position 0 before the sync doesn't seem
to help.

If you look at sync() as simply invalidating the read buffer (isn't
that right?), isn't it illogical for it to fail in this situation?

Besides sync() doesn't flush the write buffer (on a read-write
stream), does it? Similarly, flush() doesn't invalidate the read
buffer, does it?

I'm using g++ 3.3.2 on Mandrake Linux 10; kernel 2.6.

-kartik
Jul 22 '05 #1
1 2401
On 29 Oct 2004 21:46:40 -0700, ka*************@yahoo.com (kartik)
wrote in comp.lang.c++:
I open an fstream in read-only mode, read till the end, then try to
sync() before seeking to position 0 & reading again. But the sync
fails. I discovered that clear()ing the stream before the sync causes
the sync to work. Seeking to position 0 before the sync doesn't seem
to help.

If you look at sync() as simply invalidating the read buffer (isn't
that right?), isn't it illogical for it to fail in this situation?

Besides sync() doesn't flush the write buffer (on a read-write
stream), does it? Similarly, flush() doesn't invalidate the read
buffer, does it?

I'm using g++ 3.3.2 on Mandrake Linux 10; kernel 2.6.

-kartik


Attempting to read past the end of file sets the fail bit on the
stream. All operations on the stream, including sync(), will fail
until clear() is used to remove the fail bit.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2

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

Similar topics

3
by: David Blasdell | last post by:
This appears very strange to me, I'm having a problem with a fstream object inside a class which is not being called directly from main (another class calls the class that contains the fstream...
3
by: ratzeel | last post by:
The following snippet code throws an error while compiling on SUN os.. Any idea how to resolve this... #include <iostream.h> #include <fstream.h> #include <math.h> #include <algorithm>...
2
by: NewToCPP | last post by:
I am having some trouble including "iostream" "fstream" to my code. I tried the following ways and base times it did not work. What is the problem? test.cc: ======= ..... #include...
9
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
2
by: jjcp | last post by:
I would like to say thanks in advance for insight anyone can shed on this for me. Long story short from time to time I need to us C++ to take a list of file and make an index out of them in...
7
by: Soneji | last post by:
*sigh* Ok, I have two questions. First, my setup: Win-doze XP-SP2; & Dev-C++ 4.9.9.2; I recently started trying to use 'fstream' to work my input/output, and I noticed that using the...
6
by: Gaijinco | last post by:
Should this do something? #include <fstream> #include <string> int main() { std::fstream filestr ("test.txt", std::fstream::in | std::fstream::out); std::string s="";
3
by: Ioannis Vranos | last post by:
Hi, I am experimenting with fstream type, I have written the following code: #include <iostream> #include <fstream> #include <string> int main() { using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.