C++对文件进行读写操作

版权声明:github博客地址https://ryanlee0129.github.io/wtf-blog/ 引用请注明 https://blog.csdn.net/u013288800/article/details/82597275

C++对文件进行读写操作

    std::ifstream infile;   //输入流
    infile.open(conf, std::ios::in);
    if(!infile.is_open ())
    {
        std::cout << "Open file failure" << std::endl;
    }
    else
    {
        while (!infile.eof())            // 若未到文件结束一直循环
        {
            infile >> res;
        }
        infile.close();   //关闭文件
        if(res == "true")
        {
            std::ofstream openfile(conf);
            openfile<<"false";
            openfile.close();
        }
    }

猜你喜欢

转载自blog.csdn.net/u013288800/article/details/82597275