Sign in to follow this  
Tertsi

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this