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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top