hi guys i am new at C++ and i am right now learning about vectors. i created 2 vectors which deposit high scores for a game, and while i try to merge them it keeps reporting me an error number 3094. the code i use is.
int main()
{
vector<int>::const_iterator iter;
cout << "Creating a list of scores.";
vector<int> scores;
scores.push_back(7500);
scores.push_back(1500);
scores.push_back(3500);
cout << "Merging both lists.";
// need container big enough to hold results
merge(scores.begin(), scores.end(), moreScores.begin(), moreScores.end(), allScores.begin());
cout << "all high scores: " << endl;
for (iter = allScores.begin(); iter != allScores.end(); ++iter)
cout << *iter << endl;
return 0;
}
the problem is at the merge cause when i cut it by making it a comment with double slash the program doesnt produce an error..
For the function to yield the expected result, the elements in the both ranges shall already be ordered according to the same strict weak ordering criterion (operator< or comp). The resulting range is also sorted according to it
Your scores are backwards, and thus, considered unsorted. If you want them sorted backwards, use the comp parameter with either an object that overloads operator() to return a bool if the first parameter goes before the second, or a function pointer that does the same.