Daily C++11: Raw string literals

Ever wondered how many backslashes are in “\\\\\\\\”? Me too, because that’s how you have to write a regular expression to correspond to two backslashes. And I am bad at counting especially after 10 hours of work, with my head stuck in the monitor.

C++11 makes things a bit simpler when it comes to special characters. Behold the raw literals, that should make life a little easier, especially for people writing paths for windows programs (although, guys, / works just as fine as \ in Win32 APIs last time I checked). A raw literal is a string representation that makes special characters not so special, and interprets them literally. For example,

will contain

To add a new line, you can add it in the text directly (by putting a new line before the closing parenthesis) or by concatenation with a normal string literal:

Tomorrow’s episode will be on customizing string literals, and combining with literal types.

Comments are closed.