
C++中ifstream导入txt文件问题
用ifstream导入了一个实际存在并且文件内有文字的的txt文件,用cout将其打印出来,运行时无错误,为什么显示的不是txt文件里的文字,而是一把X??#includ...
用ifstream导入了一个实际存在并且文件内有文字的的txt文件,用cout将其打印出来,运行时无错误,为什么显示的不是txt文件里的文字,而是一把X??
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(array<System::String ^> ^args)
{
ifstream fin("wordsconsolidation.txt");
char ch;
while(!fin.eof())
{
fin>>ch;
cout<<ch;
}
int temp;
cin>>temp;
return 0;
} 展开
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(array<System::String ^> ^args)
{
ifstream fin("wordsconsolidation.txt");
char ch;
while(!fin.eof())
{
fin>>ch;
cout<<ch;
}
int temp;
cin>>temp;
return 0;
} 展开
展开全部
这种默认是二进制流输入的,编码方式就不对,最好找找那种专门解析汉字编码的读入方式~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你确定文件打开成功吗?
最好加个if(!fin) cout<<"open failed."<<endl;
最好加个if(!fin) cout<<"open failed."<<endl;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用什么格式进行输出的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询