C++ //练习 10.35 使用普通迭代器逆序打印一个vector。

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

练习 10.35 使用普通迭代器逆序打印一个vector。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex10.35.cpp
	> Author: 
	> Mail: 
	> Created Time: Thu 14 Mar 2024 03:21:49 PM CST
 ************************************************************************/

#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
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 numbers: ";
    for(auto iter = number.crbegin(); iter != number.crend(); ++iter){
        cout<<*iter<<" ";
    }
    cout<<endl;

    return 0;
}
运行结果显示如下
相关推荐
汉克老师7 小时前
GESP2023年9月认证C++三级( 第一部分选择题(9-15))
c++·gesp三级·gesp3级
星越华夏7 小时前
python——三角函数用法
开发语言·python
代码中介商7 小时前
C语言数据存储深度解析:从原码反码补码到浮点数存储
c语言·开发语言·内存
We་ct7 小时前
LeetCode 120. 三角形最小路径和:动态规划详解
前端·javascript·算法·leetcode·typescript·动态规划
py有趣7 小时前
力扣热门100题之和为K的子数组
数据结构·算法·leetcode
hipolymers8 小时前
C语言怎么样?难学吗?
c语言·数据结构·学习·算法·编程
workflower9 小时前
机器人应用-楼宇室内巡逻
大数据·人工智能·算法·microsoft·机器人·动态规划·享元模式
ZPC82109 小时前
fanuc 机器人通过PR寄存器实现轨迹控制
人工智能·算法·计算机视觉·机器人
py有趣9 小时前
力扣热门100题之编辑距离
数据结构·算法·leetcode
2501_9333295510 小时前
企业级舆情监测系统技术解析:Infoseek数字公关AI中台架构与实践
开发语言·人工智能·自然语言处理·架构