如何在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP