G's profile我曾经是好孩子PhotosBlogListsMore Tools Help

G

Occupation
Location
Interests
我有轻度的自闭症和抑郁症
还有 中度的妄想症 不要靠近
No list items have been added yet.

我曾经是好孩子

世界末日之后 我变成了坏孩子 还在废墟上哭泣
There are no photo albums.
May 29

谈论 UNICODE/Wide Characters handling in C++

 

引用

UNICODE/Wide Characters handling in C++

I was bitten again.

Life was never meant to be easier, and it's tougher when you come to deal with wide characters in C++ with wfstream, wcout or any other WIDE versions of standard I/O facilities.

Two Rule of Thumbs:

#1 Unicode files must be opened as binary

Example:

std::wifstream xmlFile(m_FileName, ios::binary);

std::wofstream xmlFile(m_FileName, ios::binary);

#2 when working with languages other than English, wifstream/wofstream must be imbued with a non-default facet to read from or write to a real UNICOE file, or else wofstream ends up writing an ANSI file.

An explanation is available from here .

Example:

  1:  wstring ws(L"this is a wide string"); 
  2:  wofstream of_imbued;
  3: 
  4:  IMBUE_NULL_CODECVT(of_imbued); 
  5: 
  6:  of_imbued.open(L"c:\\imbued.txt", ios::binary);
  7:  of_imbued<<ws.c_str(); 
  8: 
  9:  wofstream of_not_imbued;
 10:  of_not_imbued.open(L"c:\\not_imbued.txt", ios::binary);
 11:  of_not_imbued<<ws.c_str();
 12: 

Outputs of the above code:

Two imbue facilities are available:

- Boost Library

- imbue_null_codecvt (the one used in above example)

There's also a classical  C way to write UNICODE files:

  1: wchar_t myWString[] = L"Some strange characters." 
  2: fwrite(myWString, sizeof(wchar_t), sizeof(myWString)/sizeof(wchar_t), 
  3: myFile ); 

However, it is not portable.

References:

  1. Unicode Implementation

http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/ffe0912d1462d7a5/7601a62008fdd25a?lnk=st&q=wfstream+fstream+cout+wcout&rnum=6&hl=en#7601a62008fdd25a

  1. Unicode in C++

http://groups.google.com/group/comp.lang.c++/browse_thread/thread/f4a6a434b0453187/1edc2bc1f4187597?lnk=st&q=wfstream+fstream+cout+wcout&rnum=3&hl=en#1edc2bc1f4187597

  1. how to read a Unicode file with fstream?

http://groups.google.com/group/microsoft.public.vc.stl/browse_thread/thread/45d7520ec3ad3f51/d57b41e9abb20117?lnk=st&q=wfstream+fstream+cout+wcout&rnum=2&hl=en#

  1. A very puzzling problem: cout vs. wcout, fstream vs. wfstream

http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/37c3e24861ca09e3/78fe0aeed7b728de?lnk=st&q=wfstream+fstream+cout+wcout&rnum=1&hl=en#78fe0aeed7b728de

  1. Upgrading an STL-based application to use Unicode

http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp

January 30

在生活

我甚至不能说服自己,这样是快乐的。

January 23

阳光下

人的大脑总是要被占着的。不是被生活的热情充满,就会被无聊的空虚占有。

时时刻刻都在模仿别人,时时刻刻都在学习所谓的先进,最后停下来的时候发现,自己已经面目全非。想哭都不知道用怎样的表情。

那天醒来的时候好像没有很痛,一切都像是在梦里撕杀,只留下心悸,没有伤痕。

这些年来一直很无聊,总是看着别人轻而易举地拿走自怎么努力也得不到的东西,越是在意,就越会失望。

大家都在做着自己的事情,看起来都做的很好,这样就有一个错觉,好像我是个托后腿的。也许不是什么错觉,或许是事实。

明天的明天的明天的时候,还是想着昨天的昨天的昨天的事。一直都忘不了。

我的梦想在哪里我也不知道,大家好像都有自己的梦想。没有梦想怎么生活,没有生活哪来梦想 。这个“鸡生蛋蛋生鸡”的问题很是让人讨厌。

有种直觉,哪里不对,但究竟是哪里却不知道。真TMD想骂人,好像这样才可以松下来。

不一定吧。习惯这句话了。好像我生活里没有什么可以确定。这里的小孩太聪明了,已经没有什么一定的了。

长大了么?希望还是不要了,已经不想再长大了。昨天的昨天的昨天的事。

November 14

无聊的时候

一梦三四年 醒来的时候 原来是这么的无聊啊 好多事情等着去做 再也不能像小时候一样 玩赖不去做任何事情 那时候做事情是没有代价的 而现在 I'm paying the price myself
今天就很无聊 不知道想去做什么 我在学习黑客技术  这是唯一能让我忘了一切的东西 唯一能让我沉溺其中的东西
忘掉 然后 思考
August 29

Lost

还是看不到很远的地方 已经许久 还是没有梦想 实现 开始怀疑自己 怀疑 怀疑 不可理解的怀疑 那一天看到了亦小桉的大学生活
我开始失落 开始放弃 开始努力 开始像一个愤青一样 开始变得自己也不认识 我不知道怎么过今后的日子 我的生活真的会这样结束么
以前的梦想一直在眼前 一直在住前 好像很近 好像很远 不知道 不觉得 自己已经没有力气了 怎么了 这个世界 不喜欢这个世界
 
自己也不认识的世界 以前不是这样的 我也不知道为什么会这样 这个世界已经不是以世界了
我也没办法了 路在何方了
 
 
 
 
by 
感谢访问!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
菠萝wrote:
不知道你会不会上来看
高考 加油 万福
June 3