C++ //练习 17.2 定义一个tuple,保存一个string、一个vector<string>和一个pair<string, int>。

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

练习 17.2 定义一个tuple,保存一个string、一个vector和一个pair<string, int>。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex17.2.cpp
	> Author: 
	> Mail: 
	> Created Time: Fri 16 Aug 2024 08:48:44 AM CST
 ************************************************************************/

#include<iostream>
#include<tuple>
#include<vector>
using namespace std;

int main(){
    tuple<string, vector<string>, pair<string, int>> t("print", {"Hello", " World"}, {" program", 2});
    cout<<get<0>(t)<<" ";
    for(const auto &s : get<1>(t)){
        cout<<s;
    }
    cout<<get<2>(t).first<<" "<<get<2>(t).second<<endl;

    return 0;
}
运行结果显示如下:
相关推荐
程序猿_极客2 小时前
【2025 年最新版】Java JDK 安装与环境配置教程(附图文超详细,Windows+macOS 通用)
java·开发语言·windows·macos·jdk
一个不知名程序员www5 小时前
算法学习入门 --- 哈希表和unordered_map、unordered_set(C++)
c++·算法
二哈喇子!5 小时前
BOM模型
开发语言·前端·javascript·bom
C++ 老炮儿的技术栈6 小时前
在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?
c语言·c++·windows·git·vscode·visual studio
二哈喇子!6 小时前
空指针异常
开发语言
咚为6 小时前
Rust Print 终极指南:从底层原理到全场景实战
开发语言·后端·rust
%xiao Q6 小时前
GESP C++五级-202406
android·开发语言·c++
Psycho_MrZhang6 小时前
Neo4j Python SDK手册
开发语言·python·neo4j
Traced back6 小时前
# C# + SQL Server 实现自动清理功能的完整方案:按数量与按日期双模式
开发语言·c#
Sarvartha6 小时前
C++ STL 栈的便捷使用
c++·算法