在这里,我们将看到如何在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