Archived

This topic is now archived and is closed to further replies.

Laroche

Ifstream seekg()

Recommended Posts

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..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
file.seekg( 0, ios::beg );
file.seekg( 0, ios::end );

int dis = file.tellg();

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

Share this post


Link to post
Share on other sites