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

ppt做会动彩字网站怎样在百度发广告贴

ppt做会动彩字网站,怎样在百度发广告贴,wordpress 游戏网页,医疗器械网1. 关键词2. filesystem.h3. filepath.cpp6. 测试代码7. 运行结果8. 源码地址 1. 关键词 关键词: C 文件路径处理 路径拼接 获取父目录的路径 获取文件名 获取拓展名 跨平台 应用场景: 路径的拼接路径的解析 2. filesystem.h #pragma once#include…
  • 1. 关键词
  • 2. filesystem.h
  • 3. filepath.cpp
  • 6. 测试代码
  • 7. 运行结果
  • 8. 源码地址

1. 关键词

关键词:

C++ 文件路径处理 路径拼接 获取父目录的路径 获取文件名 获取拓展名 跨平台

应用场景:

  • 路径的拼接
  • 路径的解析

2. filesystem.h


#pragma once#include <string>
#include <iostream>
#include <cstdio>
#include "filetype.h"namespace cutl
{/*** @brief The class for file path operations.**/class filepath{public:/*** @brief Construct a new filepath object** @param path file path string*/filepath(const std::string &path);/*** @brief Construct a new filepath object by copy** @param other other filepath object*/filepath(const filepath &other);/*** @brief Assign operator, assign a new filepath object by copy** @param other other filepath object* @return filepath& the reference of the current filepath object*/filepath &operator=(const filepath &other);/*** @brief Destroy the filepath object**/~filepath() = default;public:/*** @brief Get the path separator of the current os platform.** @return the path separator*/static char separator();/*** @brief Get the string of the filepath.** @return the filepath*/std::string str() const;/*** @brief Join the current filepath with a new filename.** @param filename the filename to be joined* @return the new filepath object*/filepath join(const std::string &filename) const;/*** @brief Get the parent directory of the filepath.** @return parent directory path*/std::string dirname() const;/*** @brief Get the filename or directory name of the filepath.** @return filename or directory name*/std::string basename() const;/*** @brief Get the extension of the filepath.** @return extension with dot*/std::string extension() const;private:std::string filepath_;};/*** @brief Define the output stream operator for filepath object.** @param os the std::ostream object* @param fp the filepath object to be output* @return std::ostream& the reference of the std::ostream object after outputing the filepath object.*/std::ostream &operator<<(std::ostream &os, const filepath &fp);/*** @brief Create a filepath object from a string.** @param path file path string* @return filepath object*/filepath path(const std::string &path);} // namespace cutl

3. filepath.cpp


#include "filepath.h"
#include "inner/logger.h"
#include "inner/filesystem.h"
#include "strutil.h"
#include "sysutil.h"namespace cutl
{static constexpr char win_separator = '\\';static constexpr char unix_separator = '/';void fixpath(std::string &path){if (win_separator == filepath::separator()){for (size_t i = 0; i < path.size(); i++){if (path[i] == unix_separator){path[i] = win_separator;}}}else if (unix_separator == filepath::separator()){for (size_t i = 0; i < path.size(); i++){if (path[i] == win_separator){path[i] = unix_separator;}}}else{// do nothing}while (path.empty() || path.back() == filepath::separator()){path.pop_back();}}filepath::filepath(const std::string &path){filepath_ = path;fixpath(filepath_);}filepath::filepath(const filepath &other){filepath_ = other.filepath_;}filepath &filepath::operator=(const filepath &other){this->filepath_ = other.filepath_;return *this;}char filepath::separator(){
#if defined(_WIN32) || defined(__WIN32__)return win_separator;
#elsereturn unix_separator;
#endif}std::string filepath::str() const{return filepath_;}filepath filepath::join(const std::string &filename) const{std::string path = filepath_ + separator() + filename;return filepath(path);}std::string filepath::dirname() const{auto index = filepath_.find_last_of(separator());if (index == std::string::npos){return "";}return filepath_.substr(0, index);}std::string filepath::basename() const{auto index = filepath_.find_last_of(separator());// auto len = filepath_.length() - index - 1;if (index == std::string::npos){return filepath_;}return filepath_.substr(index + 1);}std::string filepath::extension() const{auto pos = filepath_.find_last_of('.');if (pos == std::string::npos){return "";}return filepath_.substr(pos);}std::ostream &operator<<(std::ostream &os, const filepath &fp){os << fp.str();return os;}filepath path(const std::string &path){return filepath(path);}
} // namespace cutl

6. 测试代码

#include "common.hpp"
#include "fileutil.h"void TestJoin()
{PrintSubTitle("TestJoin");auto path1 = cutl::path("/Users/spencer/workspace/common_util/src/usage_demo");auto path2 = path1.join("filepath.hpp");std::cout << "path1: " << path1 << std::endl;std::cout << "path2: " << path2 << std::endl;
}void TestDirnameBasename()
{PrintSubTitle("TestDirnameBasename");auto path1 = cutl::path("/Users/spencer/workspace/common_util/src/usage_demo/filepath.hpp");std::cout << "path1: " << path1 << std::endl;std::cout << "dirname: " << path1.dirname() << std::endl;std::cout << "basename: " << path1.basename() << std::endl;auto path2 = cutl::path("/Users/spencer/workspace/common_util/src/usage_demo");std::cout << "path2: " << path2 << std::endl;std::cout << "dirname: " << path2.dirname() << std::endl;std::cout << "basename: " << path2.basename() << std::endl;auto path3 = cutl::path("filepath.hpp");std::cout << "path3: " << path3 << std::endl;std::cout << "dirname: " << path3.dirname() << std::endl;std::cout << "basename: " << path3.basename() << std::endl;
}void TestExtenstion()
{PrintSubTitle("TestExtenstion");auto path1 = cutl::path("/Users/spencer/workspace/common_util/src/usage_demo/filepath.hpp");std::cout << "path1: " << path1 << ", extension: " << path1.extension() << std::endl;auto path2 = cutl::path("/Users/spencer/workspace/common_util/src/usage_demo/filepath");std::cout << "path2: " << path2 << ", extension: " << path2.extension() << std::endl;
}

7. 运行结果

----------------------------------------------TestJoin----------------------------------------------
path1: /Users/spencer/workspace/common_util/src/usage_demo
path2: /Users/spencer/workspace/common_util/src/usage_demo/filepath.hpp
----------------------------------------TestDirnameBasename-----------------------------------------
path1: /Users/spencer/workspace/common_util/src/usage_demo/filepath.hpp
dirname: /Users/spencer/workspace/common_util/src/usage_demo
basename: filepath.hpp
path2: /Users/spencer/workspace/common_util/src/usage_demo
dirname: /Users/spencer/workspace/common_util/src
basename: usage_demo
path3: filepath.hpp
dirname: 
basename: filepath.hpp
-------------------------------------------TestExtenstion-------------------------------------------
path1: /Users/spencer/workspace/common_util/src/usage_demo/filepath.hpp, extension: .hpp
path2: /Users/spencer/workspace/common_util/src/usage_demo/filepath, extension: 

8. 源码地址

更多详细代码,请查看本人写的C++ 通用工具库: common_util, 本项目已开源,代码简洁,且有详细的文档和Demo。

本文由博客一文多发平台 OpenWrite 发布!

http://www.yidumall.com/news/28555.html

相关文章:

  • 夺宝网站建设哪里有整站优化
  • 企业开发网站建设哪家好站长统计app下载免费
  • 大型网站设计公司全媒体广告投放平台
  • wordpress上传gifseo外包公司多吗
  • 红安县城乡建设局网站房地产网站模板
  • 网站做接口到app 价格百度自动驾驶技术
  • wordpress更换域名图片不显示广州seo软件
  • 陕煤化建设集团网站矿建二公司百度网站推广费用多少
  • 上海疫情幕后真凶深圳seo优化
  • 用jsp做网站怎么分区网站关键词查询网址
  • 宿迁网站优化排名最新中高风险地区名单
  • 哪个网站可以做行程攻略东营优化路网
  • 奢侈品网站怎么做tuig优化seo深圳网络推广
  • 做时时彩网站平台软件百度官方免费下载安装
  • 滁州建设厅网站中国网站建设公司前十名
  • 怎么自己建设网站口碑营销的好处
  • 室内装修免费咨询北京seo如何排名
  • 网站建设中的思想和算法seo短视频网页入口引流
  • wordpress title怎么设置搜外seo视频 网络营销免费视频课程
  • 招远市建设局网站周口网站seo
  • 哈尔滨哪里有做网站的技术培训
  • 卫生局网站模板招代理最好的推广方式
  • 网站制作案例 立邦排行榜123网
  • 包头有没有专业做淘宝网站的推广方案范例
  • 网站怎么做交易网络营销的认识
  • 网站不备案怎么做网页淘宝客百度网站下载
  • 做推广秒杀网站中国seo第一人
  • 五屏网站建设品牌好百度关键词排名优化工具
  • 辽宁建设工程信息网招标公告桓仁金山热电厂防水工程windows优化大师有用吗
  • dedecms织梦古典艺术书画书法公司企业网站源码模板seo门户网站