What will be the output of the following C++ code using std::string?
#include <iostream>
#include <string>
using namespace std;
int main() {
string s1 = "Hello";
string s2 = "World";
cout << s1 + " " + s2;
return 0;
}
Options
-
A.
HelloWorld
-
B.
Hello World
-
C.
Error
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
Hello World
Detailed Explanation
Correct Answer: Option B — Hello WorldExplanation: The std::string class supports concatenation with the + operator. The expression combines s1, a space, and s2 to produce Hello World.