Writing to the end of a c++file

Hello, I made an entry in a file from one class, but you need to add the results from the second class to the same file, the results are superimposed and as a result, only the results of the second class are in the file. How do I write to the end of a file? We use ios_base:: app???? Thank you Brave_Lime for the answer.

 std::ofstream vmdelet_out;     //создаем поток 
 vmdelet_out.open("file.txt", std::ios::app);  // открываем файл для записи 
 в конец
 vmdelet_out << "Exit"; // сама запись
 vmdelet_out.close();   // закрываем файл
Author: HiHello, 2017-05-08

1 answers

Record

std::ofstream vmdelet_out;                    //создаем поток 
vmdelet_out.open("file.txt", std::ios::app);  // открываем файл для записи в конец
vmdelet_out << "Exit";                        // сама запись
vmdelet_out.close();                          // закрываем файл

Line-by-line reading

#include <iostream>
#include <fstream>
#include <string>

int main(void)
{
    std::fstream f;                     // создаем поток
    f.open("file.txt", std::ios::in);   // открываем файл для чтения
    if (f)                              // если файл открылся
    {
        std::string buf;                // создаем буфер, куда будет считываться информация
        while (getline(f, buf))         //  Пока мы получили строку - тело цикла исполняется ||  когда файл закончился (все строки считались) - цикл false
        {
             std::cout << buf;          // выводит последнюю прочитанную строку
             //... остальные ваши действия     
        }
    }
}

I hope it helped!

 3
Author: Brave_Lime, 2017-05-08 17:38:08