C ++ character line feed

Source: Internet
Author: User

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:

  1. Add a backslash '\' to the string line feed, and there cannot be spaces or tabs before the next line;
  2. 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.