c打开指定路径文件_C++ 读取指定路径下所有的文件 (C++ get the list of files in a directory)...
電腦配置: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)過來,習(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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python k-means聚类分析_p
- 下一篇: esxi时区设置 +8_Go语言MySQ