Cpp_Primer_Answers icon indicating copy to clipboard operation
Cpp_Primer_Answers copied to clipboard

练习9.4答案有误

Open Noicdi opened this issue 4 years ago • 3 comments

while (begin++ != end) { if (*begin == i) return true; } 在这段循环中,begin迭代器被++,导致在接下来的查找操作中无法对vector的第一个元素进行判断。

Noicdi avatar Mar 03 '21 08:03 Noicdi

会忽略vector中的第一个元素,对后续元素进行对比判断

Noicdi avatar Mar 03 '21 09:03 Noicdi

do { 
    if (*begin == i) 
        return true; 
} while (begin++ != end)

这样呢

RekiDunois avatar Mar 05 '21 07:03 RekiDunois

do { 
    if (*begin == i) 
        return true; 
} while (begin++ != end)

这样呢

我看没问题,我是这样解决的 while (begin != end) if (*begin++ == i) return true;

Noicdi avatar Mar 06 '21 01:03 Noicdi