Read from file but not move pointer

J

John

Guys,

As title says, I need to read from a file but don't want to move the
file pointer. I know I can use rewind or fseek to move back in file but
is there a function that allows you to read but not actually move the
file pointer (or auto reset the pointer back to original pre read position)?

Cheers,

John.
 
R

Roland Pibinger

As title says, I need to read from a file but don't want to move the
file pointer. I know I can use rewind or fseek to move back in file but
is there a function that allows you to read but not actually move the
file pointer (or auto reset the pointer back to original pre read position)?

Write a reusable function that does what you want using fread, ftell,
fseek.
 
J

Jeffrey Baker

John said:
Guys,

As title says, I need to read from a file but don't want to move the file
pointer. I know I can use rewind or fseek to move back in file but is
there a function that allows you to read but not actually move the file
pointer (or auto reset the pointer back to original pre read position)?

Cheers,

John.

What about seekg( n, io:cur) should keep it in position once there when n is
set to 0.
 
J

James Kanze

As title says, I need to read from a file but don't want to
move the file pointer. I know I can use rewind or fseek to
move back in file but is there a function that allows you to
read but not actually move the file pointer (or auto reset the
pointer back to original pre read position)?

By definition, it wouldn't be a stream if the pointer didn't
advance. (FWIW, I don't know of an OS which provides this
functionality either.) The only solution is to use tellg() to
get the original position, and then seekg() to return to it.
 

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

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,243
Latest member
Weeb3PRAgency

Latest Threads

Top