如何在 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