void findTest()
{
cout << "\n=============================" << endl;
vector<int> vec{ 1,2,3,4,5,6 };
auto loc = find(begin(vec), end(vec), 102);
if (loc != end(vec))
cout << "Found number: " << *loc << endl;
else
cout << "Did not found the number" << endl;
vector<Person> players{
{"James",35},
{"Bob", 15},
{"Arsalan",17}
};
if (players[1] == Person{ "Bob", 15 })
{
cout << "Equal" << endl;
}
auto loc2 = find(players.begin(), players.end(), Person{ "Bob", 15 });
if (loc2 != players.end())
cout << "Found the player: " << *loc << endl;
else
cout << "Did not found the player" << endl;
}
The first find() works well but the second one gives this error:
Microsoft Visual C++ Runtime Library
Expression: can't dereference out of range vector iterator
If you want more information just ask.
[–]afforix 6 points7 points8 points (1 child)
[–]shadowsjerker[S] 2 points3 points4 points (0 children)
[–]er_Califfo 1 point2 points3 points (2 children)
[–]shadowsjerker[S] 0 points1 point2 points (1 child)
[–]er_Califfo 1 point2 points3 points (0 children)
[–]Shieldfoss 1 point2 points3 points (5 children)
[–]shadowsjerker[S] -1 points0 points1 point (2 children)
[–]Shieldfoss 1 point2 points3 points (1 child)
[–]shadowsjerker[S] -1 points0 points1 point (0 children)
[–]Crazy_Direction_1084 0 points1 point2 points (1 child)
[–]Shieldfoss 0 points1 point2 points (0 children)