How can i put break line in string.
Something like this.
string var = "hey
s";
Would be something like this.
hey
s
Place the cursor where you want the line break. Use the keyboard shortcut – ALT + ENTER (hold the ALT key and then press Enter).
In Python, the new line character “\n” is used to create a new line. When inserted in a string all the characters after the character are added to a new line. Essentially the occurrence of the “\n” indicates that the line ends here and the remaining characters would be displayed in a new line.
There is carriage return with the escape sequence \r with hexadecimal code value 0D abbreviated with CR and line-feed with the escape sequence \n with hexadecimal code value 0A abbreviated with LF. Text files on MS-DOS/Windows use CR+LF as newline. Text files on Unix/Linux/MAC (since OS X) use just LF as newline.
You should just put a \n
between hey
and s
. So:
string var = "hey\ns";
Line breaking can be achieved using Dan's advice:
string var = "hey\ns";
Note that you cannot do this the way you wanted:
string var = "hey // this is not
s"; // valid code
and it's a design choice of C++.
Older languages generally do not allow you to define multiline strings.
But, for example, Python does allow you exactly this:
someString = """
this is a
multiline
string
"""
and printing someString
will give you a true multiline string.
You can forget about this when using C++, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With