大家看看我这个wchar_t char之间互换的程序哪里错了

Super.Jiju 2010-04-21 11:01:28

#include<iostream>
#include<string>
#include<wchar.h>
#include<locale.h>


using namespace std;

void ctow(wchar_t *dest, char *src )
{
int size = 200;
mbstowcs(dest, src, size);
}

void wtoc(char *dest, wchar_t *src )
{
wcstombs(dest, src, 200);
}

int main()
{
setlocale( LC_ALL, "en_US.UTF-8" );

char aa[300] = "测试psp3000如何";

wchar_t bb[201];
char cc[300];

ctow(bb,aa);
wtoc(cc,bb);

cout<<cc<<endl;
return 0;
}




谢谢
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
白云飘飘飘 2010-04-21
  • 打赏
  • 举报
回复
setlocale( LC_ALL, "chs" );
或setlocale( LC_ALL, "" );

白云飘飘飘 2010-04-21
  • 打赏
  • 举报
回复
mbstowcs是将多字节字符(一般指本地字符编码)转化为宽字节字符(一般指unicode)字符,转换时必须指定本地字符集。在你这里就是中文字符集,setlocale( LC_ALL, "" );指使用系统的字符集。setlocale( LC_ALL, "chs" );中"chs"是VC的写法,你的编译器一定有类似的写法。
Super.Jiju 2010-04-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lhcwjy 的回复:]

setlocale( LC_ALL, "chs" );
或setlocale( LC_ALL, "" );
[/Quote]

第一个好像不起作用
第二个可以

可以解释一下吗?
另外在我的编译环境下不可以识别wstring
不知道为什么

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧