Reading - File Handling

Please help, when i save the file, it succesfully saved what i wanted, but when
opening/reading it in the compiler, it gives weird symbol to the st[itemcount].name and some random numbers in st[itemcount].total.
I tried opening the created notepad in the files, but it contained the right text. only in the compiler have issues.

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
  void save(struct Player st[], int itemcount)
{
	ofstream myfile;
	myfile.open("leaderboard.txt");
  	if(myfile.is_open()){
  	myfile << left << setw(20) << "NAME" << setw(20) << "SCORE" << endl;
	for(int i=0; i <=42; i++)
	myfile << "-";
	myfile << endl;
	myfile << left << setw(20) << st[itemcount].name << setw(20) << st[itemcount].total;
    myfile.close();
	}
}

void leaderboard()
{
	ifstream inFile;
	vector< string >sVec;
	inFile.open( "leaderboard.txt", std::ios::in );
	if( inFile.is_open() ){
		string input;
		while( inFile.good() ){
			while ( getline (inFile,input) ){
      	cout << input << '\n';
    		}
		}
		inFile.close();
	} 
}
Last edited on
What is the value of itemcount? Is your "write" function supposed to write the whole array or just one element?

Why the array instead of a vector in your "write" funciton, you seem to be able to use vector in your "read" function so why not use a vector.
Last edited on
Topic archived. No new replies allowed.