C++ Primer(第5版) 练习 10.34
练习 10.34 使用reverse_iterator逆序打印一个vector。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
/*************************************************************************
> File Name: ex10.34.cpp
> Author:
> Mail:
> Created Time: Thu 14 Mar 2024 11:23:38 AM CST
************************************************************************/
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
int main(){
vector<int> number;
int num;
cout<<"Enter numbers: ";
while(cin>>num){
number.push_back(num);
if(cin.get() == '\n'){
break;
}
}
cout<<"Reverse output: ";
for(auto r_iter = number.crbegin(); r_iter != number.crend(); ++r_iter){
cout<<*r_iter<<" ";
}
cout<<endl;
return 0;
}