码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-10-18 18:16:22      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   sp   文件   

bubuko.com,布布扣

bubuko.com,布布扣

 


  #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 << "\n";

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

    return 0;
}

 

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

标签:style   blog   http   color   io   os   ar   sp   文件   

原文地址:http://www.cnblogs.com/lucasysfeng/p/4033439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!