Jump to content
  • Advertisement

Archived

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

Laroche

Ifstream seekg()

This topic is 5622 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!