23 const vector<float>& vec,
const string& fileName,
bool append,
bool byRows)
25 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
38 const vector<double>& vec,
const string& fileName,
bool append,
bool byRows)
40 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
53 const vector<int>& vec,
const string& fileName,
bool append,
bool byRows)
55 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
68 const vector<size_t>& vec,
const string& fileName,
bool append,
bool byRows)
70 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
74 os::fprintf(f, byRows ?
"%u " :
"%u\n", static_cast<unsigned int>(*it));
83 std::vector<double>& vec,
const std::string& fileName,
bool byRows)
85 FILE* f =
os::fopen(fileName.c_str(),
"r");
92 size_t readed = fscanf(f, byRows ?
"%lf" :
"%lf\n", &number);
93 if ((!byRows) || (readed == 1)) vec.push_back(number);
134 if (!vec.empty()) of.
WriteBuffer(&vec[0],
sizeof(vec[0]) * vec.size());
size_t ReadBuffer(void *Buffer, size_t Count)
Reads a block of bytes from the stream into Buffer.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::vector< uint8_t > vector_byte
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
int void fclose(FILE *f)
An OS-independent version of fclose.
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
bool vectorToBinaryFile(const vector_byte &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
const Scalar * const_iterator
This CStream derived class allow using a file as a write-only, binary stream.
GLsizei const GLchar ** string
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool vectorFromTextFile(std::vector< double > &vec, const std::string &fileName, const bool byRows=false)
Load a std::vector from a text file (compat.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
bool vectorToTextFile(const std::vector< float > &vec, const std::string &fileName, bool append=false, bool byRows=false)
A useful function for debugging, which saves a std::vector into a text file (compat.
bool loadBinaryFile(vector_byte &out_data, const std::string &fileName)
Loads a entire file as a vector of bytes.