中文簡體轉繁體

石教兵發表於2020-11-13

中文簡體轉繁體

#include <Windows.h> 
#include <iostream>
using namespace std;

//中國->中國
char* Simple2Tra(char* szBuf)
{
	if (!strcmp(szBuf, ""))
		return NULL;
	int nReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, szBuf, -1, NULL, 0);
	char *pcBuf = new char[nReturn];
	LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, szBuf, -1, pcBuf, nReturn);
	return pcBuf;
}

//中國->中國
char* Tra2Simple(char* szBuf)
{
	if (!strcmp(szBuf, ""))
		return NULL;
	int nReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, szBuf, -1, NULL, 0);
	char *pcBuf = new char[nReturn];
	LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, szBuf, nReturn, pcBuf, nReturn);
	return pcBuf;
}

void main()
{
	char* simWord = "中國我是大笨豬石教兵的哈代表薩卡的擴散法師";
	char* traWord = Simple2Tra(simWord);
	cout << simWord << "->" << traWord << endl;

	char* simWord2 = Tra2Simple(traWord);
	cout << traWord << "->" << simWord2 << endl;

	getchar();
}

相關文章