mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 04:44:34 +03:00
P.1: The index result of a std::find-like loop needs to be initialized to -1.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user