c++汉字的unicode码

来源:互联网 发布:网络机顶盒软件下载 编辑:程序博客网 时间:2024/05/17 16:01

最近被汉字的unicode码搞得头大。

用string从记事本里获取了汉字以后想要得到他的unicode码就那么难?

网上找了半天再加各种改才出来。把自己的贴出来吧

ifstream readfile ("test.txt");//读取文件        if (! readfile.is_open())        { cout << "Error opening file"; exit (1); }//文件打开失败提示while(getline(readfile,s,',')){xx= const_cast<char*>(s.c_str());int dwNum = MultiByteToWideChar(CP_ACP, 0, xx, -1, NULL, 0);//dwNum确认转换需要的字符长度(包括了结束符”)wchar_t *wstr = (wchar_t*)malloc(sizeof(wchar_t) * dwNum);//wstr存的unicode码包括换行的'10'MultiByteToWideChar (CP_ACP, 0, xx, -1, wstr, dwNum);//多字节字符转宽字符(Unicode)//wstr即存储的取出来的unicode码 }


最后附上帮助很大的一片文章。

http://www.chengxy.com/article/14017.html