2017-01-16 94 views
0
#include <string> 
#include <iostream> 
#include <experimental/filesystem> 

namespace fs = std::experimental::filesystem; 

int main() 
{ 
    fs::path p("/usr/include/c++/../sys/*"); 
    p = fs::canonical(p); 
} 

GCC 6.2.0編譯好了,但運行時錯誤說:爲什麼std :: experimental :: filesystem :: path不接受像「*」這樣的通配符?

terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
what(): filesystem error: cannot canonicalize: No such file or directory [/usr/include/c++/../sys/*] [/data/svn/yaoxinliu] Aborted

爲什麼std::experimental::filesystem::path不能接受像*通配符?

+2

設計的基礎是一個路徑對應於單個文件,而不是任意的一組文件。 –

回答

3

根據documentation

std::experimental::filesystem::canonical converts path p to a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links.

由於std::experimental::filesystem::canonical也必須取消引用包含在路徑中的符號鏈接,它只能接受現有的文件或目錄的路徑。

相關問題