追加提振::文件系统::路径 [英] Appending to boost::filesystem::path

查看:150
本文介绍了追加提振::文件系统::路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一定的的boost ::文件系统::在手路径,我想为一个字符串(或路径)追加到它。

 的boost ::文件系统::路径p(C:\\\\目录);
p.append(富); //应导致P中指向C:\\ dir.foo

唯一的过载的boost ::文件系统::路径的追加希望两个 InputIterator的秒。

我的解决方法到目前为止是做到以下几点:

 的boost ::文件系统::路径P2(标准::字符串(p.string())追加()。富);

我缺少的东西吗?


解决方案

 的#include<&iostream的GT;
#包括LT&;串GT;
#包括LT&;升压/ filesystem.hpp>
诠释主(){
  提高::文件系统::路径p(__FILE__);  标准::字符串new_filename = p.leaf()+.foo此时,
  p.remove_leaf()/ = new_filename;
  性病::法院LT&;< P<<的'\\ n';  返回0;
}

测试了1.37,但是的的和的 remove_leaf 的也记录在的 1.35 。你需要测试是否的最后一个组件的 P 的是文件名第一,如果它可能不是。

I have a certain boost::filesystem::path in hand and I'd like to append a string (or path) to it.

boost::filesystem::path p("c:\\dir");
p.append(".foo"); // should result in p pointing to c:\dir.foo

The only overload boost::filesystem::path has of append wants two InputIterators.

My solution so far is to do the following:

boost::filesystem::path p2(std::string(p.string()).append(".foo"));

Am I missing something?

解决方案

#include <iostream>
#include <string>
#include <boost/filesystem.hpp>


int main() {
  boost::filesystem::path p (__FILE__);

  std::string new_filename = p.leaf() + ".foo";
  p.remove_leaf() /= new_filename;
  std::cout << p << '\n';

  return 0;
}

Tested with 1.37, but leaf and remove_leaf are also documented in 1.35. You'll need to test whether the last component of p is a filename first, if it might not be.

这篇关于追加提振::文件系统::路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆