bool has_filename() const;
概要
パスにファイル名が含まれているか判定する。
戻り値
return !filename().empty();
例
POSIXベースシステムでの例
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"/foo/bar.txt", // ファイル名を含むパス
"/foo/bar/", // ディレクトリパス
"/", // ルートパスのみ
".", // カレントディレクトリ
".." // 親ディレクトリ
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.has_filename() << std::endl;
}
}
出力
"/foo/bar.txt" : true
"/foo/bar/" : false
"/" : false
"." : true
".." : true
Windowsでの例
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"C:/foo/bar.txt", // ファイル名を含むパス
"C:/foo/bar/", // ディレクトリパス
"C:", // ルートディレクトリ
".", // カレントディレクトリ
".." // 親ディレクトリ
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.has_filename() << std::endl;
}
}
出力
"C:/foo/bar.txt" : true
"C:/foo/bar/" : false
"C:" : false
"." : true
".." : true
バージョン
言語
- C++17
処理系
- Clang:
- GCC: 8.1
- Visual C++: 2017 Update 7