I am trying to change the position stream pointer for input to the beginning of a file using
Code:
encodedfile.clear();
encodedfile.seekg(0);
but after printing out encodedfile.tellg() afterwards, the pointer stays at -1 and I can't read any of the text inside the file.
Here is the declaration of the variable
Code:
std::fstream encodedfile(encodedfilename,std::fstream::in | std::fstream::out);
and this is where text is outputted to the file
Code:
while(file >> std::noskipws >> ch)
{
encodedfile << hasbinary[(unsigned int)ch].binaryencoding;
cout << hasbinary[(unsigned int)ch].binaryencoding;
}
Is there another way to return the stream pointer to the beginning or is there a way to fix my code?