-
November 28th, 2012, 12:42 AM
#1
Really stumped, data input from txt
Hi guys. I have this code.
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);
}
Now I can't put data into the array scoresort[x]. I have tried everything. When the scoresort[x] is not an array I can input data. Although when it is an array it crashes my program. It will not process the line.
This is part of the HighScore section for a game that I am currently making. Any help would greatly be appreciated.
-
November 28th, 2012, 12:55 AM
#2
Re: Really stumped, data input from txt
You did not initialise x.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|