Rel*_*lla 3 c++ boost file save boost-filesystem
所以我有一些基础boost::filesystem::path Base我想创建文件夹,如果不存在,并从字符串创建二进制文件.目前我有这样的功能:
void file_service::save_string_into_file( std::string contents, std::string name )
{
std::ofstream datFile;
name = "./basePath/extraPath/" + name;
datFile.open(name.c_str(), std::ofstream::binary | std::ofstream::trunc | std::ofstream::out );
datFile.write(contents.c_str(), contents.length());
datFile.close();
}
Run Code Online (Sandbox Code Playgroud)
它要求从目录中存在.所以我想知道如何更新我的函数boost.filesystem API以达到所需的功能?
请注意,为了使用boost :: filesystem库,您需要链接预编译的boost :: filesystem静态库和boost :: system静态库.
#include "boost/filesystem.hpp"
boost::filesystem::path rootPath ( "./basePath/extraPath/" );
boost::system::error_code returnedError;
boost::filesystem::create_directories( rootPath, returnedError );
if ( returnedError )
//did not successfully create directories
else
//directories successfully created
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4860 次 |
| 最近记录: |