[英]Expanding user path with boost::filesystem
No. 没有。
But you can implement it by doing something like this: 但您可以通过执行以下操作来实现它:
namespace bfs = boost::filesystem;
using std;
bfs::path expand (bfs::path in) {
if (in.size () < 1) return in;
const char * home = getenv ("HOME");
if (home == NULL) {
cerr << "error: HOME variable not set." << endl;
throw std::invalid_argument ("error: HOME environment variable not set.");
}
string s = in.c_str ();
if (s[0] == '~') {
s = string(home) + s.substr (1, s.size () - 1);
return bfs::path (s);
} else {
return in;
}
}
Also, have a look at the similar question suggested by @WhiteViking. 另外,看看@WhiteViking提出的类似问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.