
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++
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++
Advertisements