同一時候它定義了一個類path。正如你們所想的。這個是一個可移植的路徑表示方法,它是filesystem庫的基礎。函數
固然這樣的保證也是不可能的。或者至少昂貴的。post
#include<boost/filesystem.hpp> { boost::filesystem::path path("/test/test1"); //初始化 boost::filesystem::path old_cpath = boost::filesystem::current_path(); //取得當前程序所在文件夾 boost::filesystem::path parent_path = old_cpath.parent_path();//取old_cpath的上一層父文件夾路徑 boost::filesystem::path file_path = old_cpath / "file"; //path支持重載/運算符 if(boost::filesystem::exists(file_path)) //推斷文件存在性 { std::string strPath = file_path.string(); int x = 1; } else { //文件夾不存在; boost::filesystem::create_directory(file_path); //文件夾不存在。建立 } bool bIsDirectory = boost::filesystem::is_directory(file_path); //推斷file_path是否爲文件夾 boost::filesystem::recursive_directory_iterator beg_iter(file_path); boost::filesystem::recursive_directory_iterator end_iter; for (; beg_iter != end_iter; ++beg_iter) { if (boost::filesystem::is_directory(*beg_iter)) { continue; } else { std::string strPath = beg_iter->path().string(); //遍歷出來的文件名稱 int x=1; } } boost::filesystem::path new_file_path = file_path / "test.txt"; if(boost::filesystem::is_regular_file(new_file_path)) //推斷是否爲普通文件 { UINT sizefile = boost::filesystem::file_size(new_file_path); //文件大小(字節) int x =1; } boost::filesystem::remove(new_file_path);//刪除文件new_file_path }