File's Openmode and the Cursor position

A

Al-Burak

I hope everybody is having a fantastic X-Mas, I will hate you for that
since I have to be at the computer trying to keep my current job, grrr.
:)
OK, folks, jokes aside I have a question that might sound a bit dumb,
but I am just trying to confirm something, here I go. When opening a
'std::fstream' with the following mode:
std::ios_base::eek:ut | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?

I am asking 'cos after I open the file stream, I retrieve its cursor
position which is always at zero; no matter what the size of the file
is.
I have overcome the problem by finding the file size and then setting
the cursor at the end of the file, but this would be a work around. The
proper way would be for the 'std' to place the cursor at the end of the
file, since the file has been opened for writing, no?

Gracias muchacho y muchachas, party on!
 
P

Peter Jansson

Al-Burak said:
I hope everybody is having a fantastic X-Mas, I will hate you for that
since I have to be at the computer trying to keep my current job, grrr.
:)
OK, folks, jokes aside I have a question that might sound a bit dumb,
but I am just trying to confirm something, here I go. When opening a
'std::fstream' with the following mode:
std::ios_base::eek:ut | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?

I am asking 'cos after I open the file stream, I retrieve its cursor
position which is always at zero; no matter what the size of the file
is.
I have overcome the problem by finding the file size and then setting
the cursor at the end of the file, but this would be a work around. The
proper way would be for the 'std' to place the cursor at the end of the
file, since the file has been opened for writing, no?

Gracias muchacho y muchachas, party on!
Hi,

Could you please show us the code you have, which does not work as you
expect?

Regards,
Peter Jansson
 
P

pH

You may find that even though the cursor position does not appear to be
at the end, writing to the file causes the data to be written after the
rest of the file, even without you explicity seeking to the end.

But, as Peter says, post some code !
 
D

Dietmar Kuehl

Al-Burak said:
'std::fstream' with the following mode:
std::ios_base::eek:ut | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?

No, you are not right. The mode 'app' causes the stream to append to
the file but it does not necessarily cause positioning the current
position to the end. This is what 'ate' is for: this mode puts the
initial position at the end of the file. Possibly you want a combination
of 'ate' and 'app' but actually why bother with the position at all?
'app' should always append to the file independent of what the initial
file position is. What is your actual problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top