如何在一行上连接多个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 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志