Tutorialspoint.dev

Raw string literal in C++

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

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

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

Output:

Geeks.
For.
Geeks.

Geeks.
For.
Geeks.

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

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



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter