I guess I am understanding what a vector is.
I had a look at sort. Now I have need help understanding another thing.
When I retrieve The data in the files, it is in the form of a string. But I only want to compare a part [the score] of that string, that also when it is considered to be an float value. How can I do so?
All these methods to convert string to float were very helpful. Thanks for them.
Correct me if I am wrong, the parameter entered in string.find() has to be an string literal?
If so, how am I to search for the score, since it can be anything below 40 (i.e. upto where ever long double will allow me to go in negative).
Another thing will be that I will have to look at individual lines. Any help on how to see just a single line of the file, before continuing on to the next?
This, will store into input, everything from the current line in the file until it finds ::
file:
name::87
In your case, you'd want to have something like this:
1 2 3 4 5
getline( file, input, "::" ); //This will get the name
//save the name somewhere
getline( file, input, '\n' ); //Now the second part of the line will be saved into input up until a newline( \n ) has been reached
//Here you would convert the string input into a new, suitable variable to sort
Look in the bottom table on the site. You'll need to remake your file that the program reads from.
I tend to use the '\t', then when making the file, use a tab to seperate the data to be read.
Edit:
Ignore the "std::" before getline, I never type usingnamespace std; when I code, so std:: for me is needed.
ofstream high_score ("high_score.txt",ios::out|ios::app);
for (int x = 0;x < 14;x++)
{
UserName[x] ^= Key;
high_score << UserName[x];
}
for (longlongint x = 0;x < Name.size();x++)
{
Name[x] ^= Key;
high_score<< Name[x];
}
for (longlongint x = 0;x < 12;x++)
{
Score[x] ^= Key;
high_score << Score[x];
}
for (longlongint x = 0;x < SCORES.size();x++)
{
SCORES[x]^= Key;
high_score << SCORES[x];
}
high_score << "\n";
high_score.close();
ifstream high_scores ("high_score.txt");
while (high_scores.good())
{
string the_scores;
for (int count = 0; count < 10; ++count)
{
getline (high_scores,highscores,'\t');
for (longlongint x = 0; x < highscores.size();x++)
{
highscores[x] ^= Key;
cout << highscores[x];
}
getline (high_scores,the_scores,'\n');
for (longlongint x = 0; x < the_scores.size();x++)
{
the_scores[x] ^=Key;
cout << the_scores[x];
}
cout << endl;
}
}
user_score.close();
}
because the output is :
User Name: Nisheeth Score : 40
########
ore: 40'
....
####### denotes gibberish, or rather text that is yet in encoded form (XOR Encryption) .... repetition of the same thing as above
And there is always an extra space of about 5 lines.
By the way I haven't done any thing to sort out the scores, and the syntax is correct, the problem is somewhere in the algorithm.
Your file stream is probably becoming corrupted or ending before the conditional check in the outer most loop (while loop). Note your have 3 nested loops here. My guess is the condition in the while should be added to the outer for-loop.