c++ - Creating a highscore system using Vectors -
im learning c++ , directx 9. creating small game want have high score system, have reading , writing of files done, stuck on how sort , insert new value score vector.
my method reading files vector below:
vector<int> highscore::readfile() { int score; highscorein.open ("highscore.txt", ios::out | ios::binary); if (highscorein.is_open()) { while(highscorein>>score) { scores.push_back(score); } highscorein.close(); return(scores); } else cout << "unable open file"; }
i want function check integer passed function against 5 values storing in vector scores, insert right place in vector. on appreciated:)
assuming vector sorted largest smallest
bool insert( vector<int> &v, int n ) { ( auto = v.begin(); != v.end(), ++it ) { if ( *it < n ) { v.insert( it, n ); v.pop_back() return true; } } return false; }
Comments
Post a Comment