यहां हम देखेंगे कि 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