trouble writing a text file

This is a discussion on trouble writing a text file within the C++ Programming forums, part of the General Programming Boards category; I am writing a text file which has the number of records in it at the start and then each ...

trouble writing a text file

I am writing a text file which has the number of records in it at the start and then each record is stored at a 400 boundary - or rather should be!

In the following snippet the number of records is being updated and recorded at the start of the file OK but the string I am writing should be at 400, 800, 1200 etc but this part is not working, when I inspect the file there is only the one string and it's position varies only a little.

I am sure it must be an incorrect setting but I have tried all the ios::beg etc but none seem to make a difference

I gave up long ago trying to understand what the default behavior of the objects were. You can just mask together features you want with the pipe operator. A list of features is here: ios_base::openmode - C++ Reference.

Code:

ofstream jcout;
jcout.open (filename, ios::out | ios::app);

I still think it's good to use ofstream and ifstream though, unless you want to read and write from the same stream.