• Advertisement
Sign in to follow this  

converting the return value of out.seekp(out.tellp()) to an unsigned long (C++)

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having trouble trying to figure out a way to convert the return value of out.seekp(out.tellp()) to an unsigned long. No matter where I look I can't find a good or understandable explanation of the type pos_type that it returns. So how would I get the below line to work so I can actually save the value to a file? // ofstream out.. unsigned long int filestart = out.seekp(out.tellp());

Share this post


Link to post
Share on other sites
Advertisement
ostream::seekp returns a reference to the ostream, this is so you can do things such as:

os.seekp( 18 ).write( "boo!", 5 );

The returned value is an ostream, not an integer, so there is absolutely no way to convert it to an integer type (and there is no reason to do so anyway, because it doesn't make any sense).

On the other hand, ostream::tellp does return an offset that can be casted to and from an integer value.

Finally, out.seekp( out.tellp( ) ) does by definition leave the stream unchanged, so you could as well replace it by out.

Share this post


Link to post
Share on other sites
Thanks, not knowing that I could use tellp() without seekp was my problem which was caused by a not so well written section of a book which basically told to pass it to seekp as an argument. :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement