What is the type of string literals in C/ C++?


The string literals are the set of characters which is enclosed in double quotes(“ “). Wide-string literals are prefixed with L always.

Types of string literals −

Sr.No.String Literals & Description
1“ “
Unprefixed string literal
2L” “
Wide-string literal
3u8” “
UTF-8 encoded string literal
4u” “
UTF-16 encoded string literal
5U” “
UTF-32 encoded string literal
6R” “
Raw string literal

Here is an example of string literal in C++ language,

Example

 Live Demo

#include <cwchar>
#include <cwctype>
#include <iostream>

using namespace std;
int main() {

   wchar_t s[] = L"hello world!";
   wcout << L"The uppercase string : ”" << L"\"is ";

   for (int i = 0; i < wcslen(s); i++)
   putwchar(towupper(s[i]));

   return 0;
}

Output

Here is the output

The uppercase string : ""is HELLO WORLD!

Updated on: 25-Jun-2020

185 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements