20 const vector<float>& vec,
const string& fileName,
bool append,
bool byRows)
22 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
25 for (
float it : vec)
os::fprintf(f, byRows ?
"%e " :
"%e\n", it);
34 const vector<double>& vec,
const string& fileName,
bool append,
bool byRows)
36 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
39 for (
double it : vec)
os::fprintf(f, byRows ?
"%e " :
"%e\n", it);
48 const vector<int>& vec,
const string& fileName,
bool append,
bool byRows)
50 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
53 for (
int it : vec)
os::fprintf(f, byRows ?
"%i " :
"%i\n", it);
62 const vector<size_t>& vec,
const string& fileName,
bool append,
bool byRows)
64 FILE* f =
os::fopen(fileName.c_str(), append ?
"at" :
"wt");
67 for (
unsigned long it : vec)
68 os::fprintf(f, byRows ?
"%u " :
"%u\n", static_cast<unsigned int>(it));
77 std::vector<double>& vec,
const std::string& fileName,
bool byRows)
79 FILE* f =
os::fopen(fileName.c_str(),
"r");
86 size_t readed = fscanf(f, byRows ?
"%lf" :
"%lf\n", &number);
87 if ((!byRows) || (readed == 1)) vec.push_back(number);
int void fclose(FILE *f)
An OS-independent version of fclose.
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.