Loading...
Searching...
No Matches
ml::FileWriter Class Reference

Write text or JSON data to a file. More...

#include <Malena/Utilities/FileWriter.h>

Static Public Member Functions

static bool writeJson (const std::string &path, const json &data, int indent=4)
 Serialize data to a pretty-printed JSON file.
static bool writeText (const std::string &path, const std::string &text)
 Write a raw string to a file, overwriting any existing content.

Detailed Description

Write text or JSON data to a file.

Usage

// Write JSON
ml::json data = {{"title", "CS3A Quiz"}, {"questions", ml::json::array()}};
bool ok = ml::FileWriter::writeJson(path, data);
// Write plain text
ml::FileWriter::writeText(path, "Hello, world!");
static bool writeJson(const std::string &path, const json &data, int indent=4)
Serialize data to a pretty-printed JSON file.
static bool writeText(const std::string &path, const std::string &text)
Write a raw string to a file, overwriting any existing content.
nlohmann::json json
Alias for nlohmann::json.
Definition Json.h:32

Definition at line 25 of file FileWriter.h.

Member Function Documentation

◆ writeJson()

bool ml::FileWriter::writeJson ( const std::string & path,
const json & data,
int indent = 4 )
static

Serialize data to a pretty-printed JSON file.

Returns
true on success, false if the file could not be opened.

◆ writeText()

bool ml::FileWriter::writeText ( const std::string & path,
const std::string & text )
static

Write a raw string to a file, overwriting any existing content.

Returns
true on success, false if the file could not be opened.

The documentation for this class was generated from the following file: