So, I want to be able to use Chinese characters in my C++ program, and I need to use some type, to hold such characters beyond 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, as since a sizeof(char)
in C++, for the g++ compiler evaluates to 1, yet Chinese characters cannot be expressed in a single byte.
Why are the Chinese characters here being allowed to be housed in a char
type?
What type should be used to house Chinese characters or non-ASCII characters in C++?