I'm having a problem loading data from a text file: some fields are read from the file missing their first character.
To debug this problem I have inserted a number of tellg() calls. Unfortunately, the debugging process itself is behaving in unexpected ways.
To my dismay, the streampos returned by tellg() is affected by previous calls to tellg()!
For instance, this code snippet:
//////////////////////
//Read in colour data for this object
LoadStream >>m_Colour.x
>>m_Colour.y
>>m_Colour.z
>>m_Colour.w;
streampos TestPos = LoadStream.tellg();
//////////////////////
returns a different value for TestPos than this
code:
//////////////////////
// Additional call to tellg()
streampos TestPos2 = LoadStream.tellg();
//Read in colour data for this object
LoadStream >>m_Colour.x
>>m_Colour.y
>>m_Colour.z
>>m_Colour.w;
streampos TestPos = LoadStream.tellg();
//////////////////////
In the first case, TestPos == 526; In the second case, TestPos == 525.
This makes debugging difficult because my means of observation is affecting what is being observed!
Environment: WinNT 4.0 SP6, Visual C++ 6.0
Questions:
Is this normal behaviour (I noticed tellg() is not 'const')?
If so, how do tellg() calls affect other tellg() calls?
If not, any ideas about what is going on and how to fix it(or how to figure out what is going on)?
Are you reading the file sequentially or are you seeking back and forth in the file? If you are seeking back and forth in the file, then you probably should have the file open as a binary file. This will probalby help. (It shouldn't be necessary, but it helps in VC.)