help with reading from a file

Hey, I am making a game in c++ and I have made it so that it uses an ofstream to save your people to a text file in this format

Cassandra 6 10 7 8 1 40 20 0 0 0
Vlad 5 9 8 10 1 0 20 0 0 0

Where it says their name, followed by values for their attack, defense, level, etc. And I want to make it so that a user can type in a name of a person that they want to use again, then have the program search for that name in the text file, and extract the name and the values that follow, but I don't know how to make it search the file and do this. If I could get a little direction or an example, it'd be really appreciated.
Read the data from the file into a string. Save the players entry into a string. use the 'compare()' member function from the string library to search through the data file for the entry made by the player. While you're at it read up on the 'stoi()' function which is also part of the string library (x11).
Thanks for the help, I got it to now read line by line, and it can find the specific line based on a search with the compare(). But now I don't know how to convert the string to integers, I looked up some stuff on the stoi() function, but I can't get it to work for me. At the moment it keeps giving me the error "stoi was not declared in this scope" Here is my code for this portion. I'm sure it's just some simple thing that I don't know.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void getSave() {
	ifstream saves;
	string characterChoice, line;
	bool leave = 0;
	
	saves.open("saves.txt"); //opens the file
		
	if(saves.fail()){  //checks if the file opened right
	cout << "saves file open failed" << endl;
	return;
	}
	
	while(leave==0) {
		cout << "\nWhat character from the saves do you want to get?\n";
		cin >> characterChoice;
		
				
			size_t pos;
			while(saves.good())
			  {
				  getline(saves,line); // get line from file
				  pos=line.find(characterChoice); // search
				  if(pos!=string::npos) // string::npos is returned if string is not found
					{
						cout <<"Found!";
						cout << endl << line << endl;
						break;
					}
			  }
			  
			  cout << "\nIs this who you wanted\n1: Yes\n0: No\n";
			  cin >> leave;
		}
		
		
	int classStat = stoi(line);//supposed to convert from string to int
	
	cout << classStat << endl;
	
	
	saves.close();
	return;
}
Topic archived. No new replies allowed.