Exercises for C ++ Primer version 4 and exercises 1.6
Note: This essay is directly copied in C ++ Primer (Fourth Edition) exercise solution (full version. This is mainly for me to read it again and again later.
Exercise 1.6
Explain the following sections:
1 std: cout <"The sum of" <v1; 2 <"and" <v2; 3 <"is" <v1 + v124 <std: endl; 5
Is this code legal? If it is legal, why, if it is illegal, why?
[Answer]
This code is invalid.
Note that there are semicolons at the end of lines 1st, 2, and 4, indicating that the Code contains three statements, that is, lines 1st and 2 constitute one statement, and lines 3rd and 4 constitute one statement. "<" Is a binary operator. In statements 2nd and 3, the first "<" lacks the left operand, so it is invalid.
Add "std: cout" at the beginning of lines 2nd and 3 to correct the error.
1 std: cout <"The sum of" <v1; 2 std: cout <"and" <v2; 3 std :: cout <"is" <v1 + v124 <std: endl;