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;
}
相关推荐
Dxy12393102162 小时前
Python 使用正则表达式将多个空格替换为一个空格
开发语言·python·正则表达式
故事和你914 小时前
洛谷-数据结构1-1-线性表1
开发语言·数据结构·c++·算法·leetcode·动态规划·图论
脱氧核糖核酸__4 小时前
LeetCode热题100——53.最大子数组和(题解+答案+要点)
数据结构·c++·算法·leetcode
脱氧核糖核酸__4 小时前
LeetCode 热题100——42.接雨水(题目+题解+答案)
数据结构·c++·算法·leetcode
techdashen5 小时前
Rust项目公开征测:Cargo 构建目录新布局方案
开发语言·后端·rust
星空椰5 小时前
JavaScript 进阶基础:函数、作用域与常用技巧总结
开发语言·前端·javascript
忒可君5 小时前
C# winform 自制分页功能
android·开发语言·c#
Rust研习社5 小时前
Rust 智能指针 Cell 与 RefCell 的内部可变性
开发语言·后端·rust
王老师青少年编程5 小时前
csp信奥赛C++高频考点专项训练之贪心算法 --【线性扫描贪心】:数列分段 Section I
c++·算法·编程·贪心·csp·信奥赛·线性扫描贪心
王老师青少年编程5 小时前
csp信奥赛C++高频考点专项训练之贪心算法 --【线性扫描贪心】:分糖果
c++·算法·贪心算法·csp·信奥赛·线性扫描贪心·分糖果