C++ Online Compiler
Example: String Concatenation
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// String Concatenation #include
#include
using namespace std; int main() { // Step 1: Declare two strings string part1 = "C++ "; string part2 = "Programming"; // Step 2: Concatenate using the '+' operator string fullString = part1 + part2; cout << "Concatenated with '+': " << fullString << endl; // Step 3: Concatenate using the append() method string anotherString = "Hello"; anotherString.append(", World!"); cout << "Concatenated with append(): " << anotherString << endl; // Step 4: Concatenate a character literal string text = "Number: "; text += '5'; // Appends character '5' cout << "Concatenated with += char: " << text << endl; return 0; }
Output
Clear
ADVERTISEMENTS