栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++学习日志40------path类的操作

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++学习日志40------path类的操作

目录
  • 一、path类的操作


一、path类的操作
#include
#include
#include

int main()
{
	namespace fs = std::filesystem;
	//定义路径,使用生字符串、转移字符串、正斜杠字符串
	fs::path p1{ "E:\C_pp\hello.txt" };
	fs::path p2{ R"(E:C_pp)" };
	fs::path p3{ "E:C_pp/hello.txt" };

	//输出默认文件分隔符
	std::cout << "file separator is:  " << fs::path::preferred_separator << std::endl;

	//判断是否是常规文件,如果是,输出文件大小
	if (fs::is_regular_file(p2))
	{
		std::cout << p2 << "s size is :   " << fs::file_size(p2) << std::endl;
	}
	//判断是否是目录,如果是目录,列出其子目录
	else if (fs::is_directory(p2))
	{
		std::cout << p2 << " is a directory,includes:   " << std::endl;
		for (auto& e : fs::directory_iterator(p2))
		{
			std::cout << "   " << e.path();
		}
	}
	//判断路径是否存在
	else if (fs::exists(p2))
	{
		std::cout << p2 << " is a special filen  ";
	}
	else
	{
		std::cout << p2 << " does not exist " << std::endl;
	}
	std::cin.get();
}

结果如上图所示。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号