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;
}
运行结果显示如下
相关推荐
xyq2024几秒前
Matplotlib 绘图线
开发语言
小镇敲码人3 分钟前
探索CANN框架中TBE仓库:张量加速引擎的优化之道
c++·华为·acl·cann·ops-nn
张登杰踩4 分钟前
MCR ALS 多元曲线分辨算法详解
算法
m0_694845574 分钟前
tinylisp 是什么?超轻量 Lisp 解释器编译与运行教程
服务器·开发语言·云计算·github·lisp
平安的平安7 分钟前
面向大模型算子开发的高效编程范式PyPTO深度解析
c++·mfc
June`8 分钟前
muduo项目排查错误+测试
linux·c++·github·muduo网络库
春日见10 分钟前
如何创建一个PR
运维·开发语言·windows·git·docker·容器
C++ 老炮儿的技术栈13 分钟前
VS2015 + Qt 实现图形化Hello World(详细步骤)
c语言·开发语言·c++·windows·qt
YuTaoShao13 分钟前
【LeetCode 每日一题】3634. 使数组平衡的最少移除数目——(解法一)排序+滑动窗口
算法·leetcode·排序算法
派葛穆20 分钟前
Python-批量安装依赖
开发语言·python