练习5.4:说明下列例子的含义,如果存在问题,试着修改它。
(a). while (string::iterator iter != s.end() ) {/*…*/}
答:迭代器遍历
(b) .while (bool status = find (word)) {/*…*/}
if (!status) {/**/}
答:含义:找到word这个词,循环结束,否则进行条件判断,进入if语句
修改为
while (bool status = find (word))
{
If (!status) {/**/}
}
本文解析了使用迭代器遍历容器及通过布尔值控制循环的两种常见编程场景,并提供了改进后的代码示例。
671

被折叠的 条评论
为什么被折叠?



