Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.27 KB

ReadWriteFile_opening.md

File metadata and controls

43 lines (30 loc) · 1.27 KB

Read/write in files

The framework comes with classes to manage reading and writing in files conveniently.

File management

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();
}
Global relative path

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();
}
Remark

In case the file has an absolute path, the global relative path is ignored.

More details and examples can be found in sample007.cpp.