P.1: The index result of a std::find-like loop needs to be initialized to -1.

This commit is contained in:
Michael Park 2015-12-10 07:22:57 -05:00
parent 21b28d91ef
commit 3b29134985

View File

@ -370,7 +370,7 @@ The second version leaves the reader guessing and opens more possibilities for u
string val;
cin >> val;
// ...
int index = 0; // bad
int index = -1; // bad
for (int i = 0; i < v.size(); ++i)
if (v[i] == val) {
index = i;