473,796 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2432
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.l earn.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
584
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 object). Use the following code (stripped down from what I'm actually working on, but does has the problem I'm experiencing) Create a file called test.txt in the working directory with a few bytes of any text or data Can you explain to me why...
3
2619
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> using namespace std;
2
7154
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 <iostream.h> #include <fstream.h>
9
5292
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 since I will need to write and read from files, and I am using those files as binary files. I made a sample of what's going on (below). Without using vector, everything works fine, but with using vectors, something is going wrong somewhere!?? ...
6
17264
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
4755
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 html. for this I use fstream both for input and output. So, i have a simple file that I just change few things on and I get the output formatted to what I want. So I installed FC6 on my home system and get out my handy usb drive because i needed...
7
10102
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 default constructor ( or 'open' method ) will not create a file. ( fstream fstr("hello.dat") or fstr.open("hello.dat") ) I read on a site, that I needed to add these flags: fstream fstr("hello.dat", ios_base::trunc | ios_base::out | ios_base::in);
6
3735
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
1643
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
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7552
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.