how to read data from stored files

i've been learning c++ for about 3 weeks now and i tried to take on a pretty difficult project. the aim is to write a program to be used by banks which allows the user to register an account, withdraw and deposit. i thus made a class with username, password and account balance in private, and functions in public that can get and set these parameters. I wanted to save the ata as a class to a file but i dunno how to do that. Also, i'll need the program to be able to search through the file and work on a particular instance of the class. Again, i've no idea how to do that

okay, i can save now but still can't search through the file for a particular instance of the class. it's not in the tutorial link either
Last edited on
http://www.cplusplus.com/doc/tutorial/ -->Really, this tutorial is awesome, I don't understand why a lot of people don't look at it!

To "play" with files: http://www.cplusplus.com/doc/tutorial/files/

in short: you have to declare a fstream, and with it open the file, and you can write to it with <<, read from it with >> (or getline), seek for a concrete point in the text, bla bla

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <fstream>

fstream streamFile;
streamFile.open ("my_file.txt", ios::out);
streamFile << "USERNAME: John Travolta" <<endl <<"PASSWORD: 123456";
streamFile.close();

string fileLine;
streamFile.open ("my_file.txt", ios::in);
while (! streamFile.eof()){ //this is a controversial one, but nevermind
getline (streamFile, fileLine);
cout <<fileLine; //or whatever
}
streamFile.close();
Topic archived. No new replies allowed.