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;
}
相关推荐
曙曙学编程1 分钟前
stm32——寄存器操作,蜂鸣器原理
c语言·c++·stm32·单片机·嵌入式硬件
counting money1 小时前
JAVA泛型基础
java·开发语言·eclipse
田里的水稻1 小时前
C++_数据类型和数据结构
java·数据结构·c++
007php0071 小时前
Go语言面试:传值与传引用的区别及选择指南
java·开发语言·后端·算法·面试·golang·xcode
XerCis1 小时前
Python的RSS/Atom源解析库feedparser
开发语言·python
algonaut1 小时前
adobe acrobat 安装到使用再到PDF编辑【适合小白,只看一篇就够!!!】
java·开发语言·其他·pdf
boonya1 小时前
Java JVM核心原理与面试题解析
java·开发语言·jvm
魔都吴所谓1 小时前
【Python】根据开始时间、结束时间计算中间时间
开发语言·windows·python
notfindjob2 小时前
Opencv C++ 教程-人脸识别
c++·opencv·计算机视觉
极客智造2 小时前
OpenCV C++ 核心:Mat 与像素操作全解析
c++·人工智能·opencv