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;
}