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;
}
相关推荐
废弃的小码农7 小时前
功能测试--Day07--Python编程基础
开发语言·python
再卷也是菜7 小时前
C++17(下)
c++
fengci.7 小时前
Microweber CMS 未授权路径穿越漏洞(CVE-2026-65694)
android·开发语言·前端·学习·php
alexwang2118 小时前
HDU 4348 详细题解
c++·算法·题解·hdu·主席树·可持久化数据结构·可持久化线段树
程序员zgh8 小时前
C++ 拷贝赋值运算符 详解
c语言·开发语言·c++
念何架构之路8 小时前
restartmanager-重启管理子系统
java·开发语言
SomeB1oody9 小时前
【RustyML入门】2.0. 经典机器学习
开发语言·后端·机器学习·rust·教程
皓月斯语9 小时前
B2132 素数对
c++·算法·题解
05664610 小时前
Python高级——解释器执行原理与虚拟环境工程化实战
开发语言·python
星轨初途10 小时前
LeetCode 热题 100——day2 字母异位词分组
c++·算法·leetcode