C++ Literals
Environment:
- OS: Windows 10 Pro;
- Compiler: GCC latest.
- IDE: Code::Blocks latest.
- working on: Console applications.
My understanding for numerical literals prefixes is that they are useful to determine the numerical value type (not sure).However, I have a lot of confusion on character and string literals prefixes and suffixes. I read a lot and spent days trying to understand the situation, but I got more questions and few answers. so I thought stack overflow could be of a lot of help.
Qs:
1- What are the correct use for the string prefixes u8 u U L?
I have the following code as example:
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "\n\n Hello World! (plain) \n";
cout << u8"\n Hello World! (u8) \n";
cout << u"\n Hello World! (u) \n";
cout << U"\n Hello World! (U) \n";
cout << L"\n Hello World! (plain) \n\n";
cout << "\n\n\n";
}
The output is like this:
Hello World! (plain)
Hello World! (u8)
0x47f0580x47f0840x47f0d8
Q2: Why U u ans L has such output? I expected it is just to determine type not do encoding mapping (if it is).
Q3 Is there a simple and to the point references about encodings like UTF-8. I am confused about them, in addition I doubt that console applications is capable to deal with them. I see it is crucial to understand them.
Q4: Also I will appreciate a step by step reference that explain custom type literals.