小编Dav*_*ley的帖子

为什么 ofstream 在这里工作,而不是 fstream?

我试图了解std::ofstream和之间的区别std::fstream。我有这个代码:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
    string line;
    //create an output stream to write to the file
    //append the new lines to the end of the file
    ofstream myfileI ("input.txt", ios::app);
    
    
    if (myfileI.is_open())
    {

        myfileI << "\nI am adding a line.\n";
        cout << myfileI.fail() << "\n";
        myfileI << "I am adding another line.\n";
        cout << myfileI.fail() << "\n";

        myfileI.close();
    }
    else cout << "Unable to open file for …
Run Code Online (Sandbox Code Playgroud)

c++ iostream

0
推荐指数
1
解决办法
119
查看次数

标签 统计

c++ ×1

iostream ×1