当前位置:C++技术网 > 资讯 > 利用STL中的fstream读取小数据文本文件

利用STL中的fstream读取小数据文本文件

更新时间:2016-03-20 22:34:22浏览次数:1+次

《利用STL中的fstream来读取大数据txt文件》,一文介绍了更加详细的fstream的用法。这篇文章,我们就单单读一些小数据:
#include "iostream"
#include "fstream"
#include "windows.h"
#include "string"

using namespace std;

int main()
{
ifstream in("C:\\操作.txt",ios::binary);
if (!in.is_open())
{
cout<<"打开失败!"<<'\n';
}
else
{
ofstream out("C:\\写入9.txt",ios::binary);
if (!out.is_open())
{
cout<<"打开文件失败!"<<'\n';
}
else
{
cout<<"打开文件成功!"<<'\n';
char str[256];
while(!in.eof())
{
in.getline(str,256);
out<<str<<endl;
}
out.close();
}
}
system("pause");
return 0;
}