c++返回一个pair类型

前言

Under the new standard we can list initialize the return value.

代码测试

cpp 复制代码
#include<iostream>
#include<string>
#include<vector>

std::pair<std::string, int>
process(std::vector<std::string>& v)
{
	if (!v.empty())
	{
		return { v.back(), v.back().size() }; // list initialize返回
	}
	else
	{
		return std::pair<std::string, int>();
	}
}

int main()
{
	std::vector<std::string> vecT{ "hablee","yuki" };
	std::pair<std::string, int> re = process(vecT);
	std::cout << re.first << ", " << re.second << std::endl;

	return 0;
}
相关推荐
集成显卡8 小时前
Rust实战七 |基于带 colored 颜色文字控制台的批量文件删除工具
开发语言·后端·rust
比昨天多敲两行9 小时前
linux 线程概念与控制
java·开发语言·jvm
huaweichenai9 小时前
php 根据每个类型的抽签范围实现抽签功能
开发语言·php
codeejun10 小时前
每日一Go-73、云原生成本优化 —— 资源限制 & 指标驱动扩容
开发语言·云原生·golang
就叫_这个吧11 小时前
Java注解、元注解、自定义注解定义及应用
java·开发语言·注解
Sam_Deep_Thinking11 小时前
聊聊Java中的of
java·开发语言·架构
feng_you_ying_li14 小时前
C++复习二,继承与多态
c++
小小de风呀14 小时前
de风——【从零开始学C++】(十一):list的基本使用和模拟实现
开发语言·c++·list
三行数学14 小时前
Matlab之父克利夫·莫勒尔逝世
开发语言·matlab
陌路2014 小时前
C++高级进阶--夯实进阶基础(1)
开发语言·c++