I’m mainly working with cpp, recently. Sometimes, I have some Chinese characters in the input/output stream, the the encoding issue became annoy.
After some search, I found the way out.
the method to make your utf-8 coded program work in GBK scenario.
add the following line to your code.
#include <clocale>
#include<stdio.h>
char* dummyGlobalVarAA =std::setlocale(LC_ALL, "en_US.UTF-8");
int main(int argc, char **argv)
{
printf("abc中文\n");
return 0;
}
ref
std::setlocale - cppreference.com
https://en.cppreference.com/w/cpp/locale/setlocale
本文介绍了一种在C++程序中处理UTF-8编码在GBK环境下显示中文字符的方法。通过使用std::setlocale函数,可以确保在不同编码环境下中文字符的正确读写。这一技巧对于开发需要跨编码环境运行的C++应用程序尤其有用。
1090

被折叠的 条评论
为什么被折叠?



