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
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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- ASCII NUL, ASCII 0 ('0') and Numeric literal 0
- Integer literal in C/C++ (Prefixes and Suffixes)
- std::string::replace , std::string::replace_if in C++
- std::string::replace_copy(), std::string::replace_copy_if in C++
- std::string::append vs std::string::push_back() vs Operator += in C++
- std::string::remove_copy(), std::string::remove_copy_if() in C++
- Check if a string can be formed from another string using given constraints
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- std::string::crbegin() and std::string::crend() in C++ with Examples
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Convert a floating point number to string in C
- How to split a string in C/C++, Python and Java?
- C++ string class and its applications
- Different methods to reverse a string in C/C++
- C++ String Class and its Applications | Set 2
- Converting string to number and vice-versa in C++
- Removing spaces from a string using Stringstream
- How to convert C style strings to std::string and vice versa?
- std::string class in C++
- Conversion of Struct data type to Hex String and vice versa
Improved By : Akanksha_Rai

