如何在一行上连接多个C ++字符串?
在这里,我们将看到如何在C++的一行中连接多个字符串。有几种不同的方法可以做到这一点。最简单的方法是使用加号(+)运算符。可以使用+连接字符串。我们可以在两个字符串之间放置+号,以使其串联。
Input: Some strings “str1”, “str2”, “str3” Output: Concatenated string “str1str2str3”
算法
Step 1: Take some strings Step 2: Concatenate them by placing + sign between them Step 3: Display the string Step 4: End
范例程式码
#include <iostream>
using namespace std;
int main() {
string str1, str2, str3;
str1 = "Hello";
str2 = "C++";
str3 = "World";
string res = str1 + str2 + str3;
cout << res;
}输出结果
HelloC++World
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短