Я создал класс «Файл» для своего проекта на C++, и он основан на ofstream. Вот упрощенный код:
file.h
#include
#include
#include
#include
class File
{
private:
std::ofstream writer;
static std::mutex file_mtx;
std::filesystem::path path;
public:
File();
File(const std::filesystem::path &_path);
void write(const std::vector &lines);
};
file.cpp
File::File(const std::filesystem::path &_path) : path(_path)
{
// Create file
std::lock_guard lock(file_mtx);
writer.open(path, std::ios::app);
writer.close();
}
void File::write(const std::vector &lines)
{
std::lock_guard lock(file_mtx);
writer.open(path, std::ios::app);
if (!writer.is_open())
return;
for (const auto &line : lines)
writer
Подробнее здесь: https://stackoverflow.com/questions/791 ... ites-files