[英]Expanding user path with boost::filesystem
沒有。
但您可以通過執行以下操作來實現它:
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;
}
}
另外,看看@WhiteViking提出的類似問題 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.