Need help! C++, data from txt file into an array.
When I try an put the input data into an array it crashes my program. I can put it into a single string but not an array of strings... This is needed so I can bring all the data in to compare it and rearrange it.
Data format in file;
NAME5006
NAME3050
NAME3213
These are highScores for a game I am currently making. I want to rearrange them so they can be output in order on the highscore page.
Any help appreciated.
Code:
#include <string>
#include <iostream>
#include <fstream>
#include <math.h>
#include <sstream>
string scoresort[9];
int HighScore(int PlayerScore){
int x;
fstream scorefile ("scores.txt");
string line;
if (scorefile.is_open())
{
while (scorefile.good() )
{
getline (scorefile,line);
scoresort[x] = line.c_str();
cout << line << endl;
x++;
}
}
else {cout << "File NOT opening";}
for(int i;i < 10; i++){
cout << scoresort[0].substr (3,0) << endl;
}
scorefile.close();
// std::ostringstream o;
// o << playerscore;
return(PlayerScore);
}
Re: Need help! C++, data from txt file into an array.
You have already got an answer in your other thread.
Why do you create the second thread with the exactly the same question? :confused: