How to put interrupt string in string?

How can I put an interrupt string in a string.
Something like that.

string var = "hey s"; 

There will be something like this.

 hey s 
+4
source share
4 answers

You should just put \n between hey and s . So:

 string var = "hey\ns"; 
+9
source

The destruction of the line can be achieved with Dan's recommendation:

 string var = "hey\ns"; 

Note that you cannot do this the way you want:

 string var = "hey // this is not s"; // valid code 

and this is the design choice for C ++.

Older languages ​​usually do not allow multiline strings to be defined.

But, for example, Python allows you to do just that:

 someString = """ this is a multiline string """ 

and printing someString will give you a true multi-line string.

However, you can forget about this when using C ++.

+2
source

A line break is encoded as char '\n' . So just write \n in your line.

+1
source

you should try this string var = "hey". "/ n". s;

-4
source

Source: https://habr.com/ru/post/1333326/


All Articles