1-1: Correct
1-2: Incorrect
STD: String exclam = "! ";
STD: String message = "hello" + ", World" + exclam; error! (Error c2110: cannot add twopointers)
STD: String message = exclam + "hello" + ", World"; correct!
STD: String message = "hello" + exclam + ", World"; correct!
Question 1 and Question 2:
String-type phase +, not an addition operation, is essentially a string connection.
Originally in C ++, string constants (like "hello") are not STD: string type, but character arrays, or C-style strings.
(1) const STD: String message = "hello" + ", World"
+ Exclam;
Const STD: String message = (const char [6] + const char [8]) + STD: string );
("+" Is left-bound)
First addition: converted to const char [6] + constchar [8].
However, this addition is not defined for the Array (I .e., the addition operator is not overloaded for the array ).
Although arrays are implicitly converted to pointers, const char * + const char * does not define addition operations between two pointers.
The compiler does not know that you want to convert the result to the STD: string type.
(2) const STD: String message = exclam + "hello" + ", World"
Const STD: String message = (STD: String
+ Const char [8]) + const char [2]
The first addition is converted to STD: string + const char *. Such an addition operation is defined and the return type is STD: string. AndThe result is a string..
The second addition is converted to STD: string + const char.
========================================================== ====================================
1-3: Correct
1-4: Correct} changed to};}, no effect
1-5: Incorrect vc6 error: Error c2065: 'X': undeclaredidentifier
Explanations 3, 4, and 5:
(1) variables defined in {} are valid only in {}, and are not valid outside.
(2) The program code segment uses {} to represent a sentence. Add a ";" after a sentence, which is still a sentence.
========================================================== ====================================
1-6: