ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

C++ //练习 3.24 请使用迭代器重做3.3.3节(第94页)的最后一个练习。

2026/9/21 21:13:17 拓冰建站 浏览量
C++ //练习 3.24 请使用迭代器重做3.3.3节(第94页)的最后一个练习。

C++ Primer(第5版) 练习 3.24

练习 3.24 请使用迭代器重做3.3.3节(第94页)的最后一个练习。

环境:Linux Ubuntu(云服务器)
工具:vim

 

代码块
/*************************************************************************> File Name: ex3.24.cpp> Author: > Mail: > Created Time: Thu 01 Feb 2024 09:25:53 AM CST************************************************************************/#include<iostream>
#include<vector>
#include<cctype>
using namespace std;int main(){int num;vector<int> arr;while(cin>>num){arr.push_back(num);}for(auto beg = arr.begin(); beg != arr.end() - 1; beg = beg + 1){cout<<*beg + *(beg + 1)<<" ";}cout<<endl;for(auto beg = arr.begin(), end = arr.end() - 1; beg <= end; beg = beg + 1, end if(beg == end){cout<<*beg<<endl;}else{cout<<*beg + *end<<" ";}}return 0;
}
运行结果显示如下

在这里插入图片描述