日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 默认站点!

默认站点

當前位置: 首頁 >

boost 文件操作

發布時間:2023/12/1 30 豆豆
默认站点 收集整理的這篇文章主要介紹了 boost 文件操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果要簡單處理文件和文件夾的時候(刪除、重命名等),使用Windows的系統函數會十分麻煩,可以嘗試一下使用Boost庫來進行處理

頭文件

#include <boost/filesystem.hpp>

如果要獲得每次處理的結果錯誤碼,需要加上頭文件:

#include <boost/system/error_code.hpp> boost::system::error_code err;

如果不需要的話只需要把err去掉

以下路徑均為絕對路徑

基礎類型

boost::filesystem::path filepath;

判斷文件/文件夾是否存在:

boost::filesystem::exists(filepath, err) //true 存在 //false 不存在

判斷文件路徑是否文件夾:

boost::filesystem::is_directory(filepath, err) //true 是 //false 不是

刪除文件:

boost::filesystem::remove(filepath, err) //true 刪除成功 //false 刪除失敗

重命名文件:

boost::filesystem::rename(oldname, newname, err)

創建文件/文件夾:

boost::filesystem::create_directories(filepath, err)

獲取當前路徑:

boost::filesystem::current_path()

復制文件/文件夾:

boost::filesystem::copy(frompath, topath)

遍歷文件夾:

boost::filesystem::directory_iterator fileIter(filepath); boost::filesystem::directory_iterator enditer; for (; fileIter != enditer; ++fileIter) {//每個文件的路徑fileIter->path(); }

判斷文件是否存在父目錄

filepath.has_root_directory() //true 存在父目錄 //false 不存在

獲取當前文件路徑的父目錄

filepath.parent_path()

判斷當前文件路徑是否是 ‘.’/’…’(遍歷的時候可能用得上):

filepath.filename_is_dot() filepath.filename_is_dot_dot()

如果需要,還可以將文件路徑轉成string或wstring

filepath->string() filepath->wstring()

總結

以上是默认站点為你收集整理的boost 文件操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得默认站点網站內容還不錯,歡迎將默认站点推薦給好友。