最終更新日時(UTC):
が更新

履歴 編集

function
<filesystem>

std::filesystem::path::has_filename(C++17)

bool has_filename() const;

概要

パスにファイル名が含まれているか判定する。

戻り値

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

処理系