1#include <iostream>
2#include <string>
3#include <stdlib.h>// using c standard library
4int main()
5{
6
7 "Caleb";//String literal is a series of characters between two double quotes
8 //It is a const char array and array is just a ptr to a begining of block of memory
9 //String literals are stored in read only section of memory
10
11 const char name[8] = "Rhe\0eno";// \0 is null termination character
12 std::cout << strlen(name) << std::endl;//c function for size of string ,output => 3 due to null terminating char \0
13 std::cout << name << std::endl;// output => Rhe because null termination char \0
14
15 const char* name1 = u8"Caleb";//1 byte per char
16 const wchar_t* name2 = L"Caleb";//is 2 or 4 bytes per character dependent on compile on windows it's usually 2bytes but on linux it is 4 bytes per char
17 const char16_t* name3 = u"Caleb";//2 byte per char
18 const char32_t* name4 = U"Caleb";//4 byte per char
19
20
21 using namespace std::string_literals;
22 // this name space give number of functions for convenience
23
24 //std::string name0 = "Caleb" + "hello";//error because can't add ptr to ptr
25 std::string name0 = "Caleb"s + "hello";//s is an operator that returns std::string this will work because now adding a ptr to actual string
26 //various versions of strings
27 std::wstring namee = L"Caleb"s + L"hello";//wide string: 2 or 4 bytes depend on compiler
28 std::u32string namee32 = U"Caleb"s + U"hello";//u 32 string :4 bytes per char
29 std::u16string namee16 = u"Caleb"s + u"hello";//u16 string :2bytes per char
30 std::string namee8 = u8"Caleb";//1 byte per character
31 const char* example = R"(Line1
32Line 2
33Line 3
34Line 4
35)";//R:Raw for writing on different lines it prints escape characters
36 std::cin.get();
37
38};
1//EXAMPLE
2std::string sRaw = R"(aaa\ttt %)"; // aaa/ttt %
3std::string sNonRaw = "aaa\ttt %"; // aaa tt %
4std::cout << sRaw << "\n";
5std::cout << sNonRaw << "\n";
6
7//SYNTAX
8// R"(<string-with-raw-values>)"
9// R"(...)"