
- 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++
In C++11 and above there is a concept called Raw string. In strings we use different characters like \n, \t etc. They have different meaning. The \n is used to return the cursor to the next line, the \t generates a tab etc.
If we want to print these characters in the output without seeing the effect of them, we can use the raw string mode. To make a string to raw string we have to add "R" before the string.
Input: A string "Hello\tWorld\nC++" Output: "Hello\tWorld\nC++"
Algorithm
Step 1: Get the string Step 2: Use R before string to make it raw string Step 3: End
Example Code
#include<iostream> using namespace std; main() { string my_str = "Hello\tWorld\nC++"; string raw_string = R"Hello\tWorld\nC++"; cout << "Normal String: " << endl; cout << my_str <<endl; cout << "RAW String: " << endl; cout << raw_string; }
Output
Normal String: Hello World C++ RAW String: Hello\tWorld\nC++
- Related Articles
- Raw string literal in C++ program
- 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?
- 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
- Using sed With a Literal String Instead of an Input File

Advertisements