CString是可以正常顯示,通過WideCharToMultiByte轉過之后就變成亂碼了
CString str=_T("WX?06,600\r");
int len =WideCharToMultiByte(CP_ACP,0,str,-1,NULL,0,NULL,NULL);
char *buf =new char[len +1];
WideCharToMultiByte(CP_ACP,0,str,-1,buf,len,NULL,NULL );
uj5u.com熱心網友回復:
#include <windows.h>
#include <stdio.h>
#include <locale.h>
int main() {
setlocale(LC_ALL,"chs");
wchar_t *str=L"WX" L"\x00d8" L"06,600\r";
int len =WideCharToMultiByte(CP_ACP,0,str,-1,NULL,0,NULL,NULL);
char *buf =new char[len +1];
WideCharToMultiByte(CP_ACP,0,str,-1,buf,len,NULL,NULL );
printf("%s\n",buf);//WX?06,600
char *buf1=new char[len+2];
int i,j;
for (i=0,j=0;i<len+1;i++) {
if (buf[i]=='?') {
buf1[j]='\xa6';
buf1[j+1]='\xd5';
j+=2;
} else {
buf1[j]=buf[i];
j++;
}
}
buf1[j]=0;
printf("%s\n",buf1);//WXφ06,600
delete buf1;
delete buf;
return 0;
}
uj5u.com熱心網友回復:
#include <windows.h>
#include <stdio.h>
#include <locale.h>
int main() {
setlocale(LC_ALL,"chs");
wchar_t *str=L"WX" L"\x00d8" L"06,600\r";
int len =WideCharToMultiByte(CP_ACP,0,str,-1,NULL,0,NULL,NULL);
char *buf =new char[len +1];
WideCharToMultiByte(CP_ACP,0,str,-1,buf,len,NULL,NULL );
printf("%s\n",buf);//WX?06,600
char *buf1=new char[len+2];
int i,j;
for (i=0,j=0;i<len+1;i++) {
if (buf[i]=='?') {
buf1[j]='\xa6';
buf1[j+1]='\xb5';
j+=2;
} else {
buf1[j]=buf[i];
j++;
}
}
buf1[j]=0;
printf("%s\n",buf1);//WXΦ06,600
delete buf1;
delete buf;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/253606.html
標籤:C++ 語言
