fstream problems. cannot seek

I am trying to read a file that is just a long (34 MB) series of doubles. On the first pass, this works. I then seek back to position 0, get a new number.

Then I try to seek back to zero again and the number will not read. Can someone tell me what I am doing wrong here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

 ifileStream.open( filename ,  std::ios::binary);

       double Min=100000;
       double Max = -1*Min;
       double Value = 0;

       if (ifileStream.is_open()==true)

       {

           ifileStream.seekg(std::ios::end);
           DataLength=ifileStream.tellg();
           while (ifileStream.eof()==false )
           {
               ifileStream.read((char*)&Value,sizeof(Value));
               if (Value>Max)Max=Value;
               if (Value<Min)Min=Value;
               DataLength++;

           }
       }

       ifileStream.seekg(std::ios::beg);
       ifileStream.read((char*)&Value,sizeof(Value));
Oh, and the seek to end function returns 2, which is clearly wrong. Nothing seems to work like it is supposed to.
You're just doing it wrong.
1
2
//this is how it's supposed to look like
ifileStream.seekg(0, std::ios::end);

http://cplusplus.com/reference/iostream/istream/seekg/
Last edited on
Topic archived. No new replies allowed.