Skip to content

Commit fe28492

Browse files
committed
Updated miscellaneous.cpp
1 parent ac508fd commit fe28492

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Standard_Template_Library(stl)/Miscellaneous.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ Ans -
1414

1515
Now, node has data of next node and refer to the next to next node.
1616

17+
2 . In c++, undefined strings are char array like in const std::string message = "Hello" + "", both the "Hello" and empty string are char array and in c++, you can't concatenate two char
18+
array or one char array and one char data type but string data type can be concatenated with char array or char data type and the output will be string data type. Note: str[2] are char type.
19+
for ex;
20+
const std::string hello = "Hello";
21+
const std::string message = hello + ", world" + "";
22+
23+
it works, because the operations the compiler would see were std::string + const char[8] + const char[1]. Here, the first addition can be converted to std::string + const char*, and here the addition
24+
operator is defined, and returns a std::string. So the compiler has successfully figured out the first addition, and since the result was a string, the second addition looks like this: std::string + const char[2],
25+
and like before, this isn't possible, but the array can be converted to a pointer, and then the compiler is able to find an addition operator that works, again resulting in a std::string.
26+
27+
1728

1829

1930

0 commit comments

Comments
 (0)