大侠来啊 关于C++读取一个文件并在屏幕上显示的问题~~~

来源:百度知道 编辑:UC知道 时间:2024/05/23 19:57:40
假设现在在D盘有一个文件a.txt里面存储了一篇英文文章,现在问题是到底应该怎样读取它并在屏幕上输出呢?如果里面的文章换成中文的呢?请写出完整的程序,谢谢了 O(∩_∩)O
还有ifstream意思是不是以文件为对象然后读取此文件中的内容到 流
ofstream意思是不是以文件为对象然后将流中数据写入此 文件?
请同学们,大侠们写出完整的程序,最好能加上注释,而且请看清楚我问的每一个问题···,谢谢了
顺便说一下最好能编译一下,下面的程序我看了一遍就发现了几个错误,还有的是用C语言写的 我要的是C++··谢谢合作
还有就是输出到屏幕时到底需要哪一个函数?
谢谢大伙了··

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string s;
ifstream fin ("a.txt");
ofstream fout ("ans.txt");
while(getline(fin,s,'\n'))
fout<<s<<endl;
return 0;
}
中英文都可以

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream infile("D:\\test.txt",ios::in);
if(!infile)
{
cout << "open fail"<<endl;
return 1;
}

// infile.seekg(0, ios::end);
// int nLen = infile.tellg();
// infile.seekg(0, ios::beg);

cout << infile.rdbuf() <<endl;

return 0;
}

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream inobj("D:\\a.tx