当前位置: 首页 > 工具软件 > UTF-8 CPP > 使用案例 >

cpp work with utf-8

经和歌
2023-12-01

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

 类似资料: