// j2f.cpp : 简体(gb)==>繁体==>big5的过程 // 反向转换是类似的. // 注意直接从简体-->big5不能做到一一对应.会有很多 出现, // 故此需要先转成繁体.再转成big5. // 我感觉这种方法应当和winnt或office里提供的繁简或字符集互转是一致的. #include "stdafx.h" #include #include #include #include #include using namespace std; void j2f(const string &s) { int n=s.length (); int r=LCMapString( MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC), LCMAP_TRADITIONAL_CHINESE, s.c_str (),s.length (),NULL,0); if (!r) cout <<"error :"< char *ft=new char[r+1]; r=LCMapString( MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC), LCMAP_TRADITIONAL_CHINESE, s.c_str (),s.length (),ft,r+1);//这个api搞掂简体转繁体,下面会打印繁体出来 if (r) { ft[r]=0; cout< wchar_t *pws=new wchar_t[r+1]; int r1=MultiByteToWideChar(936,0,ft,r,pws,r+1); BOOL f=FALSE; r1=WideCharToMultiByte(950,0,pws,r1,ft,r+1," ",&f);//代码页切换搞掂gb->big5 ft[r1]=0; cout< for (int i=0;i cout<<""; printf("0x%02x ",(BYTE)ft[i]); } cout<<")"< delete [] pws; }
delete []ft; } //从标准输入简体国标-->big5繁体标准输出,输入两个空行退出 int main(int argc, char* argv[]) {
for(;;){ char line[1024]; cin.getline (line,sizeof(line)); string s(line); if (!cin ||s.length ()==0) break; j2f(s); } _getch(); return 0; } |