Francois' answer is already good, but I'd like to elaborate a little more about what's happening here...
When you put \n
in a string, that is a single character. The \
is saying "don't treat whatever comes next as you normally would, escape it." An escaped n
is a newline, so \n
is the newline character.
So if you want \
in your string, how would you get it? Normally this is treated as the escape character, but we want it to act as just a regular character. So how do we do that? We escape it! \\
will be interpreted as a single \
character.
So if you want s\nsome\n
to be printed, you need to construct your string as "s\\nsome\\n"
. Notice that the n
's aren't being escaped, the escape characters are!