习惯了c读取文件,也有必要了解一下c++读取文件
//读
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
int main ()
{
char buffer[256];
ifstream in("test.txt");
if(!in.is_open())
{
cout << "Error opening file";
return -1;
}
while(!in.eof())
{
in.getline(buffer,100);
cout << buffer << endl;
}
return 0;
}
//写
#include <fiostream.h>
int main ()
{
ofstream out("out.txt");
if(out.is_open())
{
out << "This is a line.\n";
out << "This is another line.\n";
out.close();
}
return 0;
}
c++读取 .bin
格式文件
daixu