首页 > 解决方案 > 如何从多个字符串变量中声明一个字符串 C++

问题描述

我想知道如何从多个字符串变量中声明一个字符串。

示例代码:

std::string one = "one1";
std::string two = "two2";
std::string three = "three3";

std::string OneTwoThree = (one, " ", two, " ", three); // Here I want to save it as "one1 two2 three3"
std::cout << OneTwoThree;

非常感谢任何帮助!

标签: c++variables

解决方案


您可以通过将所有三个字符串添加为

std::string OneTwoThree = one+" "+two+" "+three;

推荐阅读