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;
}
运行结果显示如下
相关推荐
自由随风飘18 小时前
python 题目练习1~5
开发语言·python
cynicme19 小时前
力扣3318——计算子数组的 x-sum I(偷懒版)
java·算法·leetcode
Bony-19 小时前
Go语言完全学习指南 - 从基础到精通------语言基础篇
服务器·开发语言·golang
ShineSpark20 小时前
Crashpad 在windows下编译和使用指南
c++·windows
fl17683120 小时前
基于python的天气预报系统设计和可视化数据分析源码+报告
开发语言·python·数据分析
ACP广源盛1392462567321 小时前
(ACP广源盛)GSV6172---MIPI/LVDS 信号转换为 Type-C/DisplayPort 1.4/HDMI 2.0 并集成嵌入式 MCU
c语言·开发语言·单片机·嵌入式硬件·音视频
不穿格子的程序员21 小时前
从零开始刷算法-栈-括号匹配
java·开发语言·
雪域迷影21 小时前
C#中通过get请求获取api.open-meteo.com网站的天气数据
开发语言·http·c#·get
yue00821 小时前
C#类继承
java·开发语言·c#
Want59521 小时前
Python汤姆猫
开发语言·python