Created
July 15, 2012 01:46
-
-
Save piaoapiao/3114351 to your computer and use it in GitHub Desktop.
转换为 unicode utf-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#include <windows.h> | |
void main() | |
{ | |
cout<<"hello world"<<endl; | |
char buf[] = "好好学习"; | |
int wc = MultiByteToWideChar(CP_ACP,0,buf,sizeof(buf),0,0); | |
unsigned short* wUnicode = new unsigned short[wc+1]; | |
wUnicode[wc] = 0; | |
int j = MultiByteToWideChar(CP_ACP,0,buf,sizeof(buf),wUnicode,wc); | |
wc = WideCharToMultiByte(CP_UTF8,0,wUnicode,sizeof(wUnicode),0,0,NULL,NULL); | |
char * sUnicode = new char [wc+1]; | |
sUnicode[wc] = 0; | |
WideCharToMultiByte(CP_UTF8,0,wUnicode,sizeof(wUnicode),sUnicode,wc,NULL,NULL); | |
cout<<wUnicode<<endl; | |
cout<<buf<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment