当前位置:   article > 正文

C++11 遍历目录下的文件_c++ 11 遍历文件夹

c++ 11 遍历文件夹

目录下文件的遍历(C++代码实现)

#include <iostream>
#include <filesystem>
using std::experimental::filesystem::v1::directory_iterator;
using std::experimental::filesystem::v1::path;

int main()
{
	int count = 0;
	for (auto &v : directory_iterator("."))
	{
		//
		std::string fileName = v.path().filename().string();
		std::cout << "fileName= " << fileName << std::endl;

		//
		std::string extensionName = v.path().extension().string();
		std::cout << "extensionName= " << extensionName << std::endl;
	}

	system("pause");
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

运行结果:
在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号