Procedure 1:
# Include <iostream>
# Include <string>
Int main ()
{
Const STD: String Hello = "hello ";
Const STD: String message = Hello + ", World" + "! ";
STD: cout <message <STD: Endl;
}
Procedure 2:
# Include <iostream>
# Include <string>
Int main ()
{
Const STD: String exclam = "! ";
Const STD: String message = "hello" + ", World" + exclam;
STD: cout <message <STD: Endl;
Return 0;
}
Are both programs correctly compiled? What is the difference?
Program 1 Compilation is normal, and program 2 Compilation is incorrect. The error type is as follows:
Error c2110: cannot add two pointers
In my understanding, a string can be used as a character container and can be added to any string or character. It is equivalent to adding a string or character to the bottom of the character container;
Character string constants cannot be added, so errors may occur. Therefore, when adding a String object to a string, at least one end must be a string object, and two strings or characters cannot be appended.