
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- Raw string literal in C++
- String Literal Vs String Object in C#
- What is a string literal in C++?
- How to define multiline String Literal in C#?
- What is Java String literal?
- Why String literal is stored in String Constant Pool in Java?
- Literal number suffixes in C#
- How to use template string literal in ECMAScript 6?
- C++ Program to Create a Dictionary with a Dictionary Literal
- What is Raw String Notation in Python regular expression?
- What is 0 (zero) - A decimal literal or An octal literal in C++
- Integer literal in C/C++ (Prefixes and Suffixes)
- What is the difference between a String object and a String literal in Java?
- How to write a short literal in C++?
- Replace value with a string literal during MongoDB aggregation operation

Advertisements