By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

File's Openmode and the Cursor position

P: n/a
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::out | 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!

Dec 28 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Al-Burak wrote:
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::out | 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
Dec 28 '05 #2

P: n/a
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 !

Dec 28 '05 #3

P: n/a
Al-Burak wrote:
'std::fstream' with the following mode:
std::ios_base::out | 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?
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Dec 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.