Raw string literals in VC++ 2013

VC++ 2013 now supports raw string literals. Note that it does not support Unicode string literals. A raw string literal allows you to avoid having to escape special characters which can be handy with HTML, XML, and regular expressions. Here’s an example usage.

auto s1 = R"(This is a "raw" string)";

Now s1 is a const char* containing the value – This is a “raw” string. It’s similar to the @ string literal support in C# although even that does not support embedded double quotes. So, what if you want to embed R”(…) in a string literal. In that case, you can use the following syntax.

auto s2 = R"QQ(Example: R"(This is my raw string)")QQ";

Now s2 contains – Example: R”(This is my raw string)”.

In this example, I’ve used QQ as a delimiter. This delimiter can be any string up to 16 characters in length. Raw string literals can contain newlines too.

auto s3 = R"(<tr>

Eventually, whenever they add support for Unicode string literals as well, you will be able to combine them and have raw Unicode string literals.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s