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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c打开指定路径文件_C++ 读取指定路径下所有的文件 (C++ get the list of files in a directory)...

發布時間:2025/3/20 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c打开指定路径文件_C++ 读取指定路径下所有的文件 (C++ get the list of files in a directory)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

電腦配置:window10, 64位操作系統,基于x64的處理器,Microsoft Visual Studio Community 2019 Version 16.4.5

實現方法:使用 boost-filessystem 包。

使用 vcpkg 安裝方法:.\vcpkg.exe install boost-filesystem:x64-windows

代碼:

#include #include using namespace std;using namespace boost::filesystem;int main(){ //指定圖片讀取文件夾,然后得到文件夾下的所有圖片 string pathImageFile = "e:/picture"; path pathFile(pathImageFile); vector<string> imageFiles; for (auto f = directory_iterator(pathFile); f != directory_iterator(); f++) { if (!is_directory(f->path())) // We eliminate directories { imageFiles.push_back(f->path().filename().string()); cout << f->path().filename().string() << endl; } else continue; }}

運行結果:

查閱了一些這方便的中文資料,發現很少談到要引用包的,所以這里寫了下使用第三方包的方法供大家參考。另外,因為本人從 python 轉過來,習慣了各式各樣的包,使用第三方包往往可以節省我們寫代碼的時間,所以本人比較喜歡使用第三方軟件。查閱了英文的資料,發現可以實現得到指定文件名下文件列表的包除了 boost-filesystem 以外還比較常用有 dirent 這個包,具體的大家可以參考以下鏈接,以上的代碼也是其中的答案之一。

https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c

總結

以上是生活随笔為你收集整理的c打开指定路径文件_C++ 读取指定路径下所有的文件 (C++ get the list of files in a directory)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。