Daily C++: More on raw string literals

Yesterday’s episode had info on the raw string literals, or, on plain english, how you can write the more complicated strings, that require strange escaping. This was done by using the R prefix, followed by quotes and an open parenthesis; the closing was done by closing the parenthesis and the quotes.

What if we want to use that precise sequence? Since escape characters don’t work, a different solution should be used.

For example, we want to print

The following will not work, since the first occurence of the first closing characters will close the first aparition of R”(.

Therefore, the standard defines a sed-like escaping method. The idea is that the general form of the raw literal definition contains extra-characters that would be repeated between quotes and parenthesis. For example:

All these versions produce the expected result.

Raw unicode literals

Raw literals can be combined with the other string type descriptor, thereby allowing ‘rawness’ for any string type supported by C++11. This means that we can have:

to describe the text

Comments are closed.