c++读取txt文档的问题

Candbasic 2008-09-10 01:36:11
在vb.net中生成student.txt ,
My.Computer.FileSystem.WriteAllText("d:\ss.txt", "20060708", False)

但为什么用C++读出来的是乱码?
string a;
ifstream in;
in.open("d:\\student.key",ios::in);
in>>a;
cout<<a;

...全文
220 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wo0011 2008-09-18
  • 打赏
  • 举报
回复
恩,应该是这个问题的
ligangok 2008-09-18
  • 打赏
  • 举报
回复
应该是编码格式的问题 Encoding有好集中编码格式,如:Default,UTF8等,你都试试,因该问题不大吧
rookieme 2008-09-15
  • 打赏
  • 举报
回复
char a[50]={0};//改一下这地方, string a;
ifstream in;
in.open("d:\\ss.txt",ios::in);
in>>a;
cout < <a;
AntingZ 2008-09-10
  • 打赏
  • 举报
回复
写的时候改成:

My.Computer.FileSystem.WriteAllText("d:\ss.txt", "20060708", False, System.Text.Encoding.Unicode)
Candbasic 2008-09-10
  • 打赏
  • 举报
回复
vc++ 项目改为多字节编码 要怎么设置吗

用word打开的话,unicode(UTF-8)才能显示正常,要读取的话,代码怎么写?
whycom 2008-09-10
  • 打赏
  • 举报
回复
try
vc++ 项目改为多字节编码
wqvbjhc 2008-09-10
  • 打赏
  • 举报
回复
vb.net生成的txt文件是什么编码格式的.
C++读的时候要判断一下是什么编码格式的,然后再根据不同编码格式读取
Candbasic 2008-09-10
  • 打赏
  • 举报
回复
错了,重发

在vb.net中生成student.txt ,
My.Computer.FileSystem.WriteAllText("d:\ss.txt", "20060708", False)

但为什么用C++读出来的是乱码?
string a;
ifstream in;
in.open("d:\\ss.txt",ios::in);
in>>a;
cout <<a;



7,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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