Raw string literal in C++

In C++, to escape characters like “\n” we use an extra “\”. From C++ 11, we can use raw strings in which escape characters (like \n \t or \” ) are not processed. The syntax of raw string is that the literal starts with R”( and ends in )”.

Let’s see an example to see raw string literal in C++:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to demonstrate working of raw string.
#include <iostream>
using namespace std;
  
int main()
{
    // A Normal string
    string string1 = "Geeks.\nFor.\nGeeks.\n"
  
    // A Raw string
    string string2 = R"(Geeks.\nFor.\nGeeks.\n)"
  
    cout << string1 << endl;
  
    cout << string2 << endl;
      
    return 0;
}

chevron_right


Output:



Geeks.
For.
Geeks.

Geeks.\nFor.\nGeeks.\n

References:
http://en.cppreference.com/w/cpp/language/string_literal

This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up

Improved By : Akanksha_Rai



Article Tags :
Practice Tags :


6


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.