file.open

Hi, I need help with data.open("Data.dat");

It`s true that when I open some file (text file) and read some values from it to some variables and then close it (data.close()) and then open it again it will start reading from that point in file where it ended last time it was opened??
Because it`s doing to me :/

How can I do that it will always start reading from the beggining of that file after I open it again ang again?? :)

Sorry for bad EN and maybe noob question :D
You could use http://www.cplusplus.com/reference/iostream/istream/seekg/
though why would you want to read the same data twice?
thanks
...:) im making a game and on logging when you write password it will cgeck it in data.dat if it is not wrong if not it will login the player if not it will return to the menu and he have to try log in second time .)

Last edited on
hmm
i did it like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
data.open("Data.dat");
data.seekg(0,ios::beg);
while(!data.eof()){
                  data>>nick;
                  acc.open(nick.c_str());
                  acc.seekg(0,ios::beg);
                  acc>>str; acc>>helper; acc>>helper;
                  cout<<"Level: "<<helper<<",  ";
                  acc>>helper; acc>>helper; acc>>helper; 
                                      .
                                      .
                  acc.close();
                  }
data.close();


it goes to the beginning once and then it didn`t goes to the beginning...
Can I have it (----.seekg(0,ios::beg); more time in program also for more variables then one?
Last edited on
Topic archived. No new replies allowed.