Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeRAD Studio

Learn How To Use C++ Raw String Literals For Windows Apps In C++ Builder

There are escape characters in C++ like “n” or “t”. When we try to print the escape characters, it will not display on the output. To show the escape characters on the output screen we use a raw string literal by using R”(String with escape characters)”. After using R in the front of the string the escape character will be displayed on the output.

From C++ 11, basically a raw string literal is a string in which the escape characters (like n t or ” ) of C++ are not processed. A raw string literal starts with R”( and ends in )”, let’s see an in an example the difference between a normal string and a raw string in C++:

The variable normal_str will be processed at compilation time so you will see three lines of text and an empty line. In the case of the variable raw_str which is a raw string literal, the compiler will not process the escape characters, so you will see a single line of text with a content identical with what you have in the C++ source code.

A first application of the concept of a raw string is in simplifying the syntax of the regular expressions. Take as an example the regular expression used in the regex tutorial for checking if the user input is an integer number. Without raw strings this is how the code should look:

Using a raw string we can simplify the above piece of code, we can get rid of the escaping characters:

Head over and get more information about C++ raw string literals in the Embarcadero DocWiki.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
C++Delphi

Measure Heart Rate Using Delphi And C++ Builder With The Power Of ThingConnect IoT Device Component Pack

C++Delphi

Create Enterprise-Grade WebSockets Based Apps With Powerful Components For Delphi

DelphiShowcase

Incredibly Powerful Enhanced Terminal And Network Toolkit For Windows Is Built In Delphi

C++CodeRAD Studio

Learn How To Use C++ Explicit Virtual Overrides In Windows Development

1 Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES