help me pls. about fstream

hi i have a text file,

information.txt
username: anything
password: something
name: blahblah

my problem is how can i store those 3 word in an variable, like in program. username = anything, password = something, name = blahblah so i can use them in my program that require a password and username to login.
Are you asking about how to parse the file or how to put it all into a struct?
im still a newbie in c++. for example the user will be ask to enter username and password to enter, the program will get his/her password in the text file.
If you want to read things from a file, you have to know where they are. For example, if you know that a user name will start on the first line, at 11th position and end with the end of line, your code could be
1
2
3
4
5
6
7
8
fstream file("fie.txt");
string uname, pass, name;
file.ignore(10);
getline(file, uname);
file.ignore(10);
getline(file, pass);
file.ignore(6);
getline(file, name);
However if you only know that a password will be written after a : and some spaces (that is, "username : bob" is a valid line), it would be a lot more complicated.
Topic archived. No new replies allowed.