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;
}
运行结果显示如下
相关推荐
x***J34819 小时前
Python多线程爬虫
开发语言·爬虫·python
AA陈超20 小时前
从0开始学习 **Lyra Starter Game** 项目
c++·笔记·学习·游戏·ue5·lyra
m***D28620 小时前
Python网络爬虫实战案例
开发语言·爬虫·python
甄心爱学习20 小时前
数据挖掘-聚类方法
人工智能·算法·机器学习
q***T58320 小时前
C++在游戏中的Unreal Engine
c++·游戏·虚幻
保持低旋律节奏20 小时前
C++——C++11特性
开发语言·c++·windows
ID_1800790547320 小时前
基于 Python 的淘宝商品详情数据结构化解析:SKU、价格与库存字段提取
开发语言·数据结构·python
星释20 小时前
Rust 练习册 82:Hamming与字符串处理
开发语言·算法·rust
时间不说谎20 小时前
c/c++的语法糖
开发语言
Laughtin20 小时前
终端Python环境的选择与切换
开发语言·python