#include "stdafx.h"
#include "iostream.h"
#include "windows.h"
#include "winnls.h"
#include "string"
using namespace std;
#pragma comment(lib, "kernel32.lib")
int main(int argc, char* argv[])
{
if (argc != 2)
{
return 1;
}
char * text = argv[1];
int cchWideChar = MultiByteToWideChar(CP_ACP,0,text,strlen(text),NULL,0) + 1;
wchar_t * lpcwStr = new wchar_t[cchWideChar];
ZeroMemory(lpcwStr, sizeof(wchar_t) * cchWideChar);
MultiByteToWideChar(CP_ACP,0,text,strlen(text),lpcwStr,cchWideChar);
cchWideChar = WideCharToMultiByte(CP_UTF8,NULL,lpcwStr,-1,NULL,0,NULL,FALSE);
char * lpMultiByteStr = new char[cchWideChar];
WideCharToMultiByte(CP_UTF8,NULL,lpcwStr,-1,lpMultiByteStr,cchWideChar,NULL,FALSE);
for (int i = 0; i < strlen(lpMultiByteStr); i++)
{
int byte = lpMultiByteStr[i];
byte = byte >=0 ? byte : 256 + byte;
cout << '%' << hex << byte;
}
cout << endl;
delete lpcwStr;
delete lpMultiByteStr;
return 0;
}