- filesystem[meta header]
- std::filesystem[meta namespace]
- path[meta class]
- function[meta id-type]
- cpp17[meta cpp]
bool has_stem() const;
パスに、拡張子を除いたファイル名が含まれているか判定する。
return !stem().empty();
- stem()[link stem.md]
- empty()[link empty.md]
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"/foo/bar.txt", // ファイル名を含むパス
"/foo/bar.tar.gz", // ファイル名に複数のドットが含まれるパス
"/foo/", // ディレクトリパス
"/foo/.", // カレントディレクトリ
"..", // 親ディレクトリ
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.has_stem() << std::endl;
}
}
- has_stem()[color ff0000]
"/foo/bar.txt" : true
"/foo/bar.tar.gz" : true
"/foo/" : false
"/foo/." : true
".." : true
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::path ps[] = {
"C:/foo/bar.txt", // ファイル名を含むパス
"C:/foo/bar.tar.gz", // ファイル名に複数のドットが含まれるパス
"C:/foo/", // ディレクトリパス
"C:/foo/.", // カレントディレクトリ
"..", // 親ディレクトリ
};
std::cout << std::boolalpha;
for (const fs::path& p : ps) {
std::cout << p << " : " << p.has_stem() << std::endl;
}
}
- has_stem()[color ff0000]
"C:/foo/bar.txt" : true
"C:/foo/bar.tar.gz" : true
"C:/foo/" : false
"C:/foo/." : true
".." : true
- C++17
- Clang:
- GCC: 8.1 [mark verified]
- Visual C++: 2017 Update 7 [mark verified]