日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

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

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

實(shí)現(xiàn)方法:使用 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; }}

運(yùn)行結(jié)果:

查閱了一些這方便的中文資料,發(fā)現(xiàn)很少談到要引用包的,所以這里寫了下使用第三方包的方法供大家參考。另外,因?yàn)楸救藦?python 轉(zhuǎn)過(guò)來(lái),習(xí)慣了各式各樣的包,使用第三方包往往可以節(jié)省我們寫代碼的時(shí)間,所以本人比較喜歡使用第三方軟件。查閱了英文的資料,發(fā)現(xiàn)可以實(shí)現(xiàn)得到指定文件名下文件列表的包除了 boost-filesystem 以外還比較常用有 dirent 這個(gè)包,具體的大家可以參考以下鏈接,以上的代碼也是其中的答案之一。

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

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。