Topic: stream to begin of file (need help)


Author: mojemj@unidhp.uni-c.dk (Mogens Jensen)
Date: 2 Feb 1995 19:14:33 GMT
Raw View
Andreas Berndsen (berndsen@solarix.iao.fhg.de) wrote:
: I`m just beginning to programm in c++.
: Now i must read a file two times.
: I set the istream.
: But when i read the file in the second time the program
: crashes.
: I think i must set the stream at the beginning of the file.

: Who can help me. To set the istream to the beginning.

: Thanks a lot

: Andreas


Example:
 ifstream file( "filename" );
 file >> alfa >> beta >> gamma;
 file.seekg( 0 );
 file.read( buffer, sizeof(buffer) );

seekg - moves the read pointer:
 seekg( pos );  // absolute (ios::beg)
 seekg( ofs, from ); // from is ios::cur or ios::beg or ios::end

seekp - moves the write pointer likewise.

tellg & tellp returns the current stream position.

consult your iostream.h...


Hope this helps...

Greetings from Jens Jakob Jensen, Denmark - (Using my fathers account)




Author: berndsen@solarix.iao.fhg.de (Andreas Berndsen)
Date: 30 Jan 1995 16:51:07 GMT
Raw View
I`m just beginning to programm in c++.
Now i must read a file two times.
I set the istream.
But when i read the file in the second time the program
crashes.
I think i must set the stream at the beginning of the file.

Who can help me. To set the istream to the beginning.

Thanks a lot

Andreas