In the C/C ++ language, a string that we may want to write is too long and put on a line affects the readability of the Code. Now we need to write many lines of books.
There are two rules for writing string multi-row books:
- Add a backslash '\' to the string line feed, and there cannot be spaces or tabs before the next line;
- Use double quotation marks.
Program example:
/*
* Introduction:
* Test the multi-row writing rule of strings in C ++.
*/
# Include <iostream>
# Include <string>
Usingnamespace STD;
Int main ()
{
// In the error example, no space exists before the next row.
Charchstr [] = "abcabc \
Abcabc ";
// Error example '\' character at the line break
Charchstr1 [] = "abcabc \
Abcabc ";
// Method 1
Charchstr2 [] = "abcabc \
Abcabc ";
// Method 2
Charchstr3 [] = "abcabc"
"Abcabc ";
Printf ("chstr []: % s \ n", chstr );
Printf ("chstr1 []: % s \ n", chstr1 );
Printf ("chstr2 []: % s \ n", chstr2 );
Printf ("chstr3 []: % s \ n", chstr3 );
String STR = "abcabc \
Abcabc ";
String str1 = "abcabc"
"Abcabc ";
Cout <"str:" <STR <Endl;
Cout <"str1:" <str1 <Endl;
Return0;
}
Output result:
Chstr []: abcabc
Chstr1 []: abcabc
Chstr2 []: abcabcabcabc
Chstr3 []: abcabcabcabc
STR: abcabcabcabc
Str1: abcabcabcabc
Press any key to continue...