void Wchar_tToString(std::string& szDst, wchar_t *wchar)
{
wchar_t * wText = wchar;
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);// WideCharToMultiByte的运用
char *psText; // psText为char*的临时数组,作为赋值给std::string的中间变量
psText = new char[dwNum];
WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);// WideCharToMultiByte的再次运用
szDst = psText;// std::string赋值
delete []psText;// psText的清除
}
int main()
{
//将6763个标准汉字读入TCHAR数组中
locale loc( "chs" );
TCHAR chiWords[CHISIZE+1];
TCHAR tmpWords[2];
wifstream file(L"AllChiWords.txt");
file.imbue(loc);
if (file.fail())
{
return 1;
}
file.getline(chiWords, sizeof(chiWords) / sizeof(chiWords[0]));
//TCHAR last = ch[CHISIZE-1];//最后一个汉字
file.close();
for(int i=0;i<CHISIZE;i++)
{
string path = "E:\\alljson2\\";
string s1;
tmpWords[0] = chiWords[i];
tmpWords[1] = '\0';
Wchar_tToString(s1,tmpWords);
path.append(s1);
path.append(".json");
geneChiWordsJson(chiWords[i],path,i);
}
//
}
return 0;
}