中文乱码的问题

kingteng 2011-04-23 08:20:42
现在有一个问题,下面的代码会让文件内容是乱码,不管是不是编码原因造成的,现在我想把文件内容读取出来,重新恢复成正常内容,该怎么做呢?
#include <string>
#include <iostream>
#include <cstring>
#include <sstream>

using namespace std;


int main()
{
FILE *f = fopen("new", "w+");
fprintf(f, "%s", "中文的.txt");
fclose(f);
return 0;
}
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
robert6757 2011-04-23
  • 打赏
  • 举报
回复
下个全面一点儿的txt修改器。就行。
AnYidan 2011-04-23
  • 打赏
  • 举报
回复
首先你要知道文件用的是什么编码
hongwenjun 2011-04-23
  • 打赏
  • 举报
回复
用 支持utf-8 的文本编辑器打开 new 和 main.cpp 看下是编码。
如果不是GBK,还是用 文本编辑器转换一下方便点
delphiwcdj 2011-04-23
  • 打赏
  • 举报
回复
我这里不是乱码

#include <string>
#include <iostream>
#include <cstring>
#include <sstream>

using namespace std;


int main()
{
FILE *f = fopen("new", "w+");
char szBuff[128]="";
fprintf(f, "%s", "中文的.txt");
rewind(f);
fgets(szBuff, sizeof(szBuff), f);// read
cout<<szBuff<<endl;
fclose(f);
return 0;
}
c_losed 2011-04-23
  • 打赏
  • 举报
回复
不大明白题意 LX继续猜

69,371

社区成员

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

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