
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Raw String Literal in C++ Program
In this article, we will be discussing the raw string literal in C++, its meaning, and examples.
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.
Example
Let’s understand this with the help of an example
#include <iostream> using namespace std; int main(){ string str = "tutorials\npoint\n" ; // A Raw string string str_R = R"(tutorials\npoint\n)"; cout <<"String is: "<<str << endl; cout <<"Raw String is: "<<str_R; return 0; }
Output
If we run the above code it will generate the following output −
String is: tutorials point Raw String is: tutorials\npoint\n
Example
#include <iostream> using namespace std; int main(){ string str = "tutorials\ttoint\t" ; // A Raw string string str_R = R"(tutorials\tpoint\t)"; cout <<"String is: "<<str << endl; cout <<"Raw String is: "<<str_R; return 0; }
Output
If we run the above code it will generate the following output −
String is: tutorials toint Raw String is: tutorials\tpoint\t
Advertisements