Load and save vectors to files (in #include <mrpt/io/vector_loadsave.h>)

// global functions

bool mrpt::io::vectorToBinaryFile(const std::vector<uint8_t>& vec, const std::string& fileName);
bool mrpt::io::loadBinaryFile(std::vector<uint8_t>& out_data, const std::string& fileName);
bool mrpt::io::loadTextFile(std::vector<std::string>& o, const std::string& fileName);
std::string mrpt::io::file_get_contents(const std::string& fileName);

bool mrpt::io::vectorToTextFile(
    const std::vector<float>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    );

bool mrpt::io::vectorToTextFile(
    const std::vector<double>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    );

bool mrpt::io::vectorToTextFile(
    const std::vector<int>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    );

bool mrpt::io::vectorToTextFile(
    const std::vector<size_t>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    );

template <class EIGEN_MATRIX>
bool mrpt::io::vectorToTextFile(
    const EIGEN_MATRIX& vec,
    const std::string& fileName
    );

bool mrpt::io::vectorNumericFromTextFile(
    std::vector<double>& vec,
    const std::string& fileName,
    const bool byRows = false
    );

Global Functions

bool mrpt::io::vectorToBinaryFile(
    const std::vector<uint8_t>& vec,
    const std::string& fileName
    )

Saves a vector directly as a binary dump to a file:

Returns:

Returns false on any error, true on everything OK.

See also:

loadBinaryFile

bool mrpt::io::loadBinaryFile(
    std::vector<uint8_t>& out_data,
    const std::string& fileName
    )

Loads a entire file as a vector of bytes.

Returns:

Returns false on any error, true on everything OK.

See also:

vectorToBinaryFile

bool mrpt::io::loadTextFile(
    std::vector<std::string>& o,
    const std::string& fileName
    )

Loads a text file as a vector of string lines.

Returns:

Returns false on any error, true on everything OK.

See also:

file_get_contents()

std::string mrpt::io::file_get_contents(const std::string& fileName)

Loads an entire text file and return its contents as a single std::string.

Relying on C++17 RVO to return a string without worring on return-by-value of big objects.

Parameters:

std::runtime_error

On any read error.

See also:

loadBinaryFile(), loadTextFile()

bool mrpt::io::vectorToTextFile(
    const std::vector<float>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    )

A useful function for debugging, which saves a numeric std::vector as a plain-text file compatible with MATLAB.

Returns:

Returns false on any error, true on everything OK.

bool mrpt::io::vectorToTextFile(
    const std::vector<double>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool mrpt::io::vectorToTextFile(
    const std::vector<int>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool mrpt::io::vectorToTextFile(
    const std::vector<size_t>& vec,
    const std::string& fileName,
    bool append = false,
    bool byRows = false
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template <class EIGEN_MATRIX>
bool mrpt::io::vectorToTextFile(
    const EIGEN_MATRIX& vec,
    const std::string& fileName
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool mrpt::io::vectorNumericFromTextFile(
    std::vector<double>& vec,
    const std::string& fileName,
    const bool byRows = false
    )

Load a numeric std::vector<double> from a text file (compat.

with MATLAB)

Returns:

Returns false on any error, true on everything OK.

See also:

loadBinaryFile