C++ reset read pointer

johnd0e

Registered
Hi everyone,
I'm looking for a way to reset the read / write pointers of an fstream (ios::in|ios::base|ios::binary) to 0 without the use of seekp(0)/ seekg(0).
(This is a small part of an assignment I have not been able to solve or find any clue on how to attack this problem. The rest is already solved.)
Below is the code I'm using right now ( with(!) seekp()|seekg()) to test the rest of the program.

Code:
void File::moveTo(uint pos)
	{ 
		if (!_file.is_open())
		{
			cout << "problem with file \n";
		}
		_actpos = _file.tellg();
		if ((pos*_recSize) < _actpos)
		{
			_file.seekp(0);
			_file.seekg(0);
			//cout << "Reset: " << _actpos << " --|--";
		}
		_actpos = _file.tellg();
		while((pos*_recSize) != _actpos)
		{
			_file.read(_recBuffer, _recSize);
			_actpos = _file.tellg();
		}		
	}

If anyone could give me a clue, hint, solution or whatever on how to solve that problem, I'd really appreciate it.

Thanks for your help in advance.
 
Well, seeing as some time has passed, your assignment should probably already be over.

So, if you're interested in getting to the start of a file without using seekp/seekg, just close the file and reopen it! That will guarantee that you'll be at the start of the file.
 
Back
Top