Ifstream seekg()

Started by
4 comments, last by Laroche 21 years, 2 months ago
I wrote a small function to get the number of characters which I use in a file:
  
int GetCharacterCount(std::ifstream& File, char Character)
{
	using namespace std;
	char ch = NULL;
	int Repetitions = 0;		

	while (!File.eof())
	{
		File.get(ch);
		if (ch == Character)
			Repetitions++;
	}

	File.seekg(0, ios::beg);

	assert(!File.eof());

	return Repetitions;
}
  
the problem is that File.seekg(0, ios::beg) isn''t setting the file pointer back to the start of the file. How can I fix this? the file is in text, not binary, so im not sure if thats the problem..
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Advertisement
noone knows?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
File.seekg(0, ios::beg);

i´m sure it does set it to the beginning.try a:
#pragma pack(1) at the beginning of the file.did it for me.

Before you call seekg(), call clear() to reset the stream to a working state.


Qui fut tout, et qui ne fut rien
Invader''s Realm
Will try that soon as I get home from work
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
file.seekg( 0, ios::beg );
file.seekg( 0, ios::end );

int dis = file.tellg();

file.seekg( 0, ios::beg );

This topic is closed to new replies.

Advertisement