vendredi 11 décembre 2020

Read from a file after have written to it with fstream - always empty

std::fstream file("filename", std::fstream::in | std::fstream::out | std::fstream::trunc);
    if (file)
    {
        file << "Some text" << std::flush;
        std::string buffer;
        //file >> buffer;
        std::getline(file, buffer);
        std::cout << buffer;
    }

I need to write to a file and read from it. After the run I can see the file with the text created, but with this code with both option how to read the buffer it is always empty. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire