Mooophy / Cpp-Primer

C++ Primer 5 answers
Creative Commons Zero v1.0 Universal
8.11k stars 3k forks source link

Incorrect use of string::size_type in ex3_17.cpp #796

Open MonsieurNeko opened 3 years ago

MonsieurNeko commented 3 years ago

In the last for loop, the loop variable has semantically no reason to be a string::size_type as we iterate a vector and not a string.

It would be better to write, for consistency with examples from the book, something like this:

for (decltype(vec.size()) i = 0; i != vec.size(); ++i)
{
    if (i != 0 && i % 8 == 0) cout << endl;
    cout << vec[i] << " ";
}