mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
P.1: The index result of a std::find
-like loop needs to be initialized to -1.
This commit is contained in:
parent
21b28d91ef
commit
3b29134985
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user