ifstream

fstream 是一个文件,
在这个文件中写了ifstream   ofstream这两个类。 
所以,你包含了fstream   就可以使用ifstream 和  ofstream。

文件的输入,就是从文件里输入到内存   用ifstream。
文件的输出,就是从内存输出到文件    用ofstream。

通俗的说:写到文件中时,用ofstream。
                  从文件里读出数据的时候用ifstream。


#include 
#include 

using namespace std;

int main()
{
    ifstream ifs;    //创建一个输入流对象
    char buf[64] = {0};


    ifs.open("sad.txt", ios::in);  //以读的方式打开文件

    if(!ifs)                       //如果不存在这个文件报错
    {
        cout<<"open failure"<>buf;
    cout<





你可能感兴趣的:(c++)