不能打印这样字符“çã”

yu3350360 2011-07-14 03:05:21

#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
char c[6]="abcçã";
std::cout<<"çã"<<std::endl;
std::cout<<c<<std::endl;
int i;
std::cin>>i;
return 0;
}


有什么好解决方案嘛?
...全文
173 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathuang68 2011-07-14
  • 打赏
  • 举报
回复
用iconv应该可以解决。下面的代码供参考:

#pragma comment(lib,"iconv.lib")
int code_convert(char *from_charset,char *to_charset,const char *inbuf, size_t inlen,char *outbuf, size_t outlen)
{
iconv_t cd;
const char **pin = &inbuf;
char **pout = &outbuf;

cd = iconv_open(to_charset,from_charset);
if (cd==0) return -1;
memset(outbuf,0,outlen);
if (iconv(cd, pin, &inlen,pout, &outlen)==-1) return -1;
iconv_close(cd);
return 0;
}

/* 示例: UTF-8 to GB2312 */
int u2g(const char *inbuf, size_t inlen, char *outbuf, size_t outlen)
{
return code_convert("UTF-8","GB2312",inbuf,inlen,outbuf,outlen);
}

/* 示例: GB2312 to UTF-8 */
int g2u(const char *inbuf, size_t inlen, char *outbuf, size_t outlen)
{
return code_convert("GB2312", "UTF-8", inbuf, inlen, outbuf, outlen);
}
yu3350360 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hai040 的回复:]
或者查下在葡文里这两个东西是什么编码
[/Quote]
这个怎么查不到啊
yu3350360 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jackyjkchen 的回复:]
改代码页吧
[/Quote]
Unicode 代码页倒是可以改的,可是改成葡萄牙文代码页,提示不能更改的。
hai040 2011-07-14
  • 打赏
  • 举报
回复
或者查下在葡文里这两个东西是什么编码
hai040 2011-07-14
  • 打赏
  • 举报
回复
把代码文件保存成葡萄牙文的格式
vc另存为可以选编码
yu3350360 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hai040 的回复:]
system("chcp 860");
std::cout << "abcçã\n";
把代码保存成葡萄牙文
.......
[/Quote]
打印出来还是不行的 后两个字符还是"??"
jackyjkchen 2011-07-14
  • 打赏
  • 举报
回复
改代码页吧
hai040 2011-07-14
  • 打赏
  • 举报
回复
system("chcp 860");
std::cout << "abcçã\n";
把代码保存成葡萄牙文
.......
ryfdizuo 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yu3350360 的回复:]

除2楼以上的方法都试过了
[/Quote]
TextOut肯定没问题。
yu3350360 2011-07-14
  • 打赏
  • 举报
回复
除2楼以上的方法都试过了
chengzhe 2011-07-14
  • 打赏
  • 举报
回复
直接用码字吧
healer_kx 2011-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hai040 的回复:]

用wchar_t,wcout试试
[/Quote]

UP
ryfdizuo 2011-07-14
  • 打赏
  • 举报
回复
控制台不行的,试试WinMain下TextOut吧。。。
hai040 2011-07-14
  • 打赏
  • 举报
回复
用wchar_t,wcout试试

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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