The framework comes with classes to manage reading and writing in files conveniently.
A file is represented by the class SlvFile
. It contains information about:
-
The name of the file . See
SlvFile::get_file_name()
-
The directory where the file virtually exists (path without file name). See
SlvFile::get_directory()
In the example below, a file is opened for writing. For reading, simply replace std::ofstream
by std::ifstream
.
SlvFile file("test-file0.xyz");
std::ofstream file_stream;
// No absolute path provided => opens ./test-file0.xyz
SlvStatus status = SlvFileMgr::open_file(file_stream, file);
if (status) {
file_stream.close();
}
A global relative path can apply to all file reading and writing:
SlvFileMgr::master_relative_path() = "../";
file.set_name("test-file1.xyz");
// No absolute path provided => opens ../test-file0.xyz
status = SlvFileMgr::open_file(file_stream, file);
if (status) {
file_stream.close();
}
In case the file has an absolute path, the global relative path is ignored.
More details and examples can be found in sample007.cpp.