(a)
string str = "Hello\nWorld";
When I print str
, the output is:
Hello
World
(b)
string str;
cin >> str; //given input as Hello\nWorld
When I print str
, the output is:
Hello\nWorld
What is the difference between (a) and (b)?
cin
does not include a C++ compiler. Escape sequences in string literals are a feature of C++'s lexer, which is part of the C++ compiler. Streams more or less give you what came from the OS (they may do some CRLF -> CR translation or similar based on the OS, but that's it).