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;
}
Ifstream seekg()
I wrote a small function to get the number of characters which I use in a file:
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..
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.
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
Qui fut tout, et qui ne fut rien
Invader''s Realm
file.seekg( 0, ios::beg );
file.seekg( 0, ios::end );
int dis = file.tellg();
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
Popular Topics
Advertisement