栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Boost之——多个值结合成一个值

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Boost之——多个值结合成一个值

C++中pair将2个数据组合成一个数据,在boost中Boost.tuple库支持该功能,且支持使用三元组、四元组和更大的类型集合。

std::tuple是C++ 11中引入的一个非常有用的结构,之前要返回一个包含不同数据类型的返回值,一般都需要自定义一个结构体或者通过函数的参数来返回,现在std::tuple可以实现该功能。

代码

// An highlighted block
#include "stdafx.h"
#include 
#include 
#include 

boost::tuple almost_a_pair(10,"Tian");
boost::tuple quad(10,1.98,23.90,1);

int _tmain(int argc, _TCHAR* argv[])
{
	//通过boost::get()函数获取值,n为从零开始索引
	int iPos = boost::get<0>(almost_a_pair);
	const std::string &str = boost::get<1>(almost_a_pair);
	std::cout<(quad)<<" "<<
		boost::get<1>(quad)<<" "<<
		boost::get<2>(quad)<<" "<<
		boost::get<3>(quad)<<" "<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/980276.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号