471,585 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,585 software developers and data experts.

File's Openmode and the Cursor position

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
3 2155
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
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
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.

Similar topics

10 posts views Thread by Steve | last post: by
11 posts views Thread by Skc | last post: by
1 post views Thread by Dan H. | last post: by
1 post views Thread by Tantra Veda | last post: by
1 post views Thread by objectref | last post: by
14 posts views Thread by Gary Nelson | last post: by
12 posts views Thread by imme929 | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.