So, I want to be able to use Chinese characters in my C ++ program, and I need to use some type to store such characters outside of the ASCII range.
However, I tried to run the following code and it worked.
#include <iostream> int main() { char snet[4]; snet[0] = 'δ½ '; snet[1] = 'η±'; snet[2] = 'ζ'; std::cout << snet << std::endl; int conv = static_cast<int>(snet[0]); std::cout << conv << std::endl; // -96 }
This doesn't make sense since with sizeof(char) in C ++, since the g ++ compiler evaluates to 1, but Chinese characters cannot be expressed in a single byte.
Why are Chinese characters allowed here to be char type?
What type should be used to place Chinese characters or non-ASCII characters in C ++?
source share