I have a game in which the main goal - to hold out as long as possible. Who lasted longer - that is supposedly the best player. After each session of the game, request the name of the player, and this information is recorded in the file top.txt in the following format:
ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ_ΡΠ΅ΠΊΡΠ½Π΄/ΠΈΠΌΡ_ΠΈΠ³ΡΠΎΠΊΠ° To make it clear, the file looks like this:
It is necessary to display the sorted results in the console. I tried sort when working with a vector like this:
vector<string> v; ifstream in("top.txt"); char buf[256]; while(in.getline(buf,256)) v.push_back(buf); std::sort(v.begin(),v.end()); std::reverse(v.begin(),v.end()); for(vector<string>::iterator s = v.begin(); s != v.end(); ++s) cout << s->c_str() << endl; That is, we sort , turn over and display all the elements. It would seem so? But the result is not the way I would like to see it:
Results with 127, 1223, 11 and 10 seconds should be higher than, for example, 9.
This is my second similar question. The first is here . The proposed option worked only when all the code was located in one main.cpp file, breaking the program into a couple of classes received errors. The same code, except that the function was used for comparison: sort(v.begin(),v.end(),compare); And the function itself is as follows:
bool Menu::compare(const string& s1, const string& s2) { return atoi(s1.c_str()) > atoi(s2.c_str()); } The code is higher in Menu.cpp, the function prototype in Menu.h:
bool compare(const std::string& s1, const std::string& s2); For a very long time, the compiler cursed string, in the end, Google gave advice that you should use std. And this is what the compiler produces for this sorting method:
Please tell me a simple way of sorting, or my cant, why such errors are incomprehensible. All that is necessary for the code will provide.
Yes, if that: Code :: Blocks 16.01, GNU GCC Compiler


