Sunday, December 4, 2011

Computer Programming: Using Unicode in C++








// 電腦程式
// 如何在C++用統一碼Unicode?
// How do we use Unicode in C++?

// Code::Blocks 10.05 運行了的代碼
// The code was built and run in Code::Blocks 10.05


// Unicode
#include "windows.h"
using namespace std;

void writeUnicodeChars(HANDLE stdout)
{
wchar_t *arr[] =
{

L"\u3007", //chinese //3007 == "zero" in UTF-16
L"\r\n", //CRLF

L"\r\n", //CRLF
L"我們美麗的河山!我們美麗的大自然!", //chinese
L"\r\n", //CRLF
0
};

for(int i=0; arr[i] != 0; i++)
{
WriteConsoleW(stdout, arr[i], wcslen(arr[i]), NULL, NULL);
}

}

int main()
{
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
if(INVALID_HANDLE_VALUE == stdout) return 1;


writeUnicodeChars(stdout);

return 0;
}

//試比較:
//Please compare:




#include
#include
#include "windows.h"
using namespace std;

int main()

{
string x = "我們美麗的河山!我們美麗的大自然!";
cout << x << endl;

return 0;
}

No comments: