语言c++标准库---fstream文件操作


  #include <fstream>

  using namespace std;

int main(int argc, char** argv)
{
    // 1 open  
    fstream objTestFile("file_test/tmp_out_app.txt", ios::in);

    // 2 is open or not
    if (!objTestFile.is_open())
    {
        cout << "open file fail" << endl;
        return -1;
    }
    
    // 3 write
    string str = "hello world";
    objTestFile << str << "
";

    // 4 first close and then clear
    objTestFile.close();
    objTestFile.clear();

    return 0;
}
原文地址:https://www.cnblogs.com/helloweworld/p/4033439.html