C++ //练习 11.12 编写程序,读入string和int的序列,将每个string和int存入一个pair中,pair保存在一个vector中。

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

练习 11.12 编写程序,读入string和int的序列,将每个string和int存入一个pair中,pair保存在一个vector中。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex11.12.cpp
	> Author: 
	> Mail: 
	> Created Time: Wed 03 Apr 2024 10:11:20 PM CST
 ************************************************************************/

#include<iostream>
#include<iomanip>
#include<utility>
#include<vector>
#include<string>
using namespace std;

int main(){
    vector<pair<string, int>> list;
    string str;
    int num;
    cout<<"Enter string and num:"<<endl;
    while(cin>>str>>num){
        list.push_back(make_pair(str, num));
    }

    cout<<endl;
    cout<<"Result: "<<endl;
    for(const auto l : list){
        cout<<setw(8)<<left<<l.first<<" "<<l.second<<endl;
    }

    return 0;
}
运行结果显示如下
相关推荐
爱写代码的刚子3 分钟前
C++知识总结
java·开发语言·c++
martian6653 分钟前
QT开发:基于Qt实现的交通信号灯模拟器:实现一个带有倒计时功能的图形界面应用
开发语言·qt
冷琴199611 分钟前
基于java+springboot的酒店预定网站、酒店客房管理系统
java·开发语言·spring boot
缘友一世18 分钟前
macOS .bash_profile配置文件优化记录
开发语言·macos·bash
tekin21 分钟前
macos 中使用macport安装,配置,切换多版本php,使用port 安装php扩展方法总结
开发语言·macos·php·port·mac多版本php安装管理·port-select
s_little_monster31 分钟前
【QT】QT入门
数据库·c++·经验分享·笔记·qt·学习·mfc
CSXB9931 分钟前
一、Python(介绍、环境搭建)
开发语言·python·测试工具·集成测试
Yingye Zhu(HPXXZYY)38 分钟前
洛谷 P11045 [蓝桥杯 2024 省 Java B] 最优分组
c++·蓝桥杯
火红的小辣椒40 分钟前
PHP反序列化7(字符串逃逸)
开发语言·web安全·php
三玖诶1 小时前
第一弹:C++ 的基本知识概述
开发语言·c++