Raw string literal in C++ - GeeksforGeeks
Raw string literal in C++
- Difficulty Level : Easy
- Last Updated : 02 Jul, 2019
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++:
// 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;
}
Output:
Geeks.For.Geeks.Geeks.\nFor.\nGeeks.\n