Skip to content

Instantly share code, notes, and snippets.

@piaoapiao
Created July 15, 2012 01:46
Show Gist options
  • Save piaoapiao/3114351 to your computer and use it in GitHub Desktop.
Save piaoapiao/3114351 to your computer and use it in GitHub Desktop.
转换为 unicode utf-8
#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