当前位置: 首页 > news >正文

利辛网站建设百度app官网下载

利辛网站建设,百度app官网下载,运营怎么自学,天津做网站的大公司C17引入了std::filesystem库(文件系统库, filesystem library)。这里整理下std::filesystem::directory_entry的使用。 std::filesystem::directory_entry,目录项,获取文件属性。此directory_entry类主要用法包括: (1).构造函数、…

      C++17引入了std::filesystem库(文件系统库, filesystem library)。这里整理下std::filesystem::directory_entry的使用。
      std::filesystem::directory_entry,目录项,获取文件属性。此directory_entry类主要用法包括:
      (1).构造函数、operator=、assign:赋值;
      (2).replace_filename: 更改目录项的文件名;
      (3).path: 返回std::filesystem::path对象;
      (4).exists: 检查指定的目录项是否存在
      (5).is_block_file、is_character_file: 检查目录项是否是块设备(block device)、字符设备(character device);
      (6).is_directory: 检查目录项是否是目录;
      (7).is_fifo: 检查目录项是否是命令管道;
      (8).is_other: 检查目录项是否是其它文件(不是常规文件、目录或符号链接);
      (9).is_regular_file: 检查目录项是否是常规文件;
      (10).is_socket: 检查目录项是否是命名套接字;
      (11).is_symlink: 检查目录项是否是符号链接;
      (12).file_size: 获取目录项指定的文件大小
      (13).last_write_time:获取目录项最后修改时间

      以下为测试代码:注意windows和linux结果输出的差异

namespace {float get_file_size(std::uintmax_t size, std::string& suffix)
{float s1 = size / 1024. / 1024 / 1024;float s2 = size / 1024. / 1024;float s3 = size / 1024.;if (s1 > 1) {suffix = " GB";return s1;}if (s2 > 1) {suffix = " MB";return s2;}if (s3 > 1) {suffix = " KB";return s3;}suffix = " Bytes";return size;
}std::string to_time_t(std::filesystem::file_time_type tp)
{using namespace std::chrono;auto sctp = time_point_cast<system_clock::duration>(tp - std::filesystem::file_time_type::clock::now() + system_clock::now());auto tt = system_clock::to_time_t(sctp);std::tm* gmt = std::localtime(&tt); // UTC: std::gmtime(&tt);std::stringstream buffer;buffer << std::put_time(gmt, "%Y-%m-%d %H:%M:%S");return buffer.str();
}} // namespaceint test_filesystem_directory_entry()
{namespace fs = std::filesystem;// 1. construct,operator=,assignfs::directory_entry d1{ fs::current_path() };fs::directory_entry d2 = d1;fs::directory_entry d3;d3.assign(fs::current_path());if ((d1 == d2) && (d1 == d3))std::cout << "they are equal" << std::endl; // they are equal// windows: d1:"E:\\GitCode\\Messy_Test\\prj\\x86_x64_vc12\\CppBaseTest"// linux: d1:"/home/spring/GitCode/Messy_Test/prj/linux_cmake_CppBaseTest"std::cout << "d1:" << d1 << std::endl;// 2. replace_filenamed1.replace_filename("C++17Test");// windows: d1:"E:\\GitCode\\Messy_Test\\prj\\x86_x64_vc12\\C++17Test"// linux: d1:"/home/spring/GitCode/Messy_Test/prj/C++17Test"std::cout << "d1:" << d1 << std::endl;// 3. pathfs::path p1 = d1.path();// windows: p1:"E:\\GitCode\\Messy_Test\\prj\\x86_x64_vc12\\C++17Test"// linux: p1:"/home/spring/GitCode/Messy_Test/prj/C++17Test"std::cout << "p1:" << p1 << std::endl;// 4. existsfor (const auto& str : { "C:\\Program Files (x86)", "/usr/local" , "E:\\GitCode\\xxx", "/usr/xxx"}) {fs::directory_entry entry{ str };/* windows:directory entry: "C:\\Program Files (x86)":existsdirectory entry: "/usr/local":does not existdirectory entry: "E:\\GitCode\\xxx":does not existdirectory entry: "/usr/xxx":does not exist *//* linux:directory entry: "C:\\Program Files (x86)":does not existdirectory entry: "/usr/local":existsdirectory entry: "E:\\GitCode\\xxx":does not existdirectory entry: "/usr/xxx":does not exist*/std::cout << "directory entry: " << entry << (entry.exists() ? ":exists\n" : ":does not exist\n");}// 5. is_block_file,is_character_file,is_directory,is_fifo,is_other,is_regular_file,is_socket,is_symlinkfor (const auto& str : { "/dev/null", "C:\\Program Files (x86)", "/usr/include/time.h", "C:\\MinGW\\bin\\c++filt.exe","/usr/bin/g++", "/dev/block/11:0"}) {fs::directory_entry entry{ str };/* windows:"C:\\Program Files (x86)" is a directory"C:\\MinGW\\bin\\c++filt.exe" is a regular_file *//* linux:"/dev/null" is a character device"/dev/null" is an other file"/usr/include/time.h" is a regular_file"/usr/bin/g++" is a regular_file"/usr/bin/g++" is a symlink"/dev/block/11:0" is a block device"/dev/block/11:0" is an other file"/dev/block/11:0" is a symlink */if (entry.is_block_file())std::cout << entry << " is a block device" << std::endl;if (entry.is_character_file())std::cout << entry << " is a character device" << std::endl;if (entry.is_directory())std::cout << entry << " is a directory" << std::endl;if (entry.is_fifo())std::cout << entry << " is a FIFO" << std::endl;if (entry.is_other())std::cout << entry << " is an other file" << std::endl;if (entry.is_regular_file())std::cout << entry << " is a regular_file" << std::endl;if (entry.is_socket())std::cout << entry << " is a named socket" << std::endl;if (entry.is_symlink())std::cout << entry << " is a symlink" << std::endl;}// 6. file_size, last_write_timefor (const auto& str : { "/usr/bin/g++", "D:\\FSCapture.exe", "D:\\DownLoad\\tmp.txt", "/usr/bin/cmake", "E:\\yulong.mp4"}) {fs::directory_entry entry{ str };/* windows:"D:\\FSCapture.exe" size: 2.82 MB"D:\\FSCapture.exe" last write time: 2016-03-29 09:26:26"D:\\DownLoad\\tmp.txt" size: 10 Bytes"D:\\DownLoad\\tmp.txt" last write time: 2023-09-26 09:00:35"E:\\yulong.mp4" size: 1.35 GB"E:\\yulong.mp4" last write time: 2023-08-19 22:42:56 *//* linux:"/usr/bin/g++" size: 910.82 KB"/usr/bin/g++" last write time: 2023-05-13 15:52:47"/usr/bin/cmake" size: 6.43 MB"/usr/bin/cmake" last write time: 2022-08-17 18:44:05 */if (entry.is_regular_file()) {std::string suffix;auto value = get_file_size(entry.file_size(), suffix);if (suffix == " Bytes")std::cout << entry << " size: " << static_cast<int>(value) << suffix << std::endl;elsestd::cout << entry << " size: " << std::fixed << std::setprecision(2) << value << suffix << std::endl;std::cout << entry << " last write time: " << to_time_t(entry.last_write_time()) << std::endl;}}return 0;
}

      执行结果如下图所示:

      GitHub:https://github.com/fengbingchun/Messy_Test

http://www.shuangfujiaoyu.com/news/63539.html

相关文章:

  • 建设网站计划书百度引流平台
  • 河南最新今日头条seo常用方法
  • 从零开始建设网站谷歌官网
  • 外包网站建设多少钱sem竞价是什么意思
  • 公益网站建设那家好危机公关处理方案
  • 做视频好用的素材网站清理大师
  • 基于php网站开发步骤seo简介
  • 武汉参开网络网站建设公司百度手机应用商店
  • 网站建设头像福鼎网站优化公司
  • 新闻网站系统源代码建立网站平台需要多少钱
  • 网站哪个服务器好南京网络营销服务
  • vs2015做网站的后端学电脑培训班
  • protected wordpress login湖南企业seo优化报价
  • 怎么做网站推广六安游戏搜索风云榜
  • 做微信活动是做网站还是做小程序好什么是seo标题优化
  • 洛阳网站建设哪家专业营销网络是什么意思
  • 做网站0基础写代码海外短视频软件
  • 电子商务以后可以做什么工作太原百度推广排名优化
  • wordpress移动端m网站如何做关键词优化
  • 四川网站开发站外seo推广
  • wordpress 全站密码嘉兴seo外包平台
  • 内蒙古自治区住房和城乡建设厅网站长沙网站优化培训
  • go做网站营销策划案例
  • 做网站和app哪个简单网站建设黄页
  • 网站定制合同和模版的区别app开发流程
  • 钢铁网站哪家做的好公司怎么在网上推广
  • 专门做家具的网站windows优化大师win10
  • 地推平台seo运营做什么
  • 哪个网站做投票链接模板好看百度推广点击收费标准
  • wordpress可以制作什么网站吗线下营销方式主要有哪些