cpp work with utf-8

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

posted on 2020-06-12 20:34  yusisc  阅读(26)  评论(0编辑  收藏  举报

导航