Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::filesystem::path::stem

      From cppreference.com
      <cpp‎ |filesystem‎ |path
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      std::filesystem::path
      Member types
      Member constants
      Member functions
      Path decomposition
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
      Helper classes
       
      path stem()const;
      (since C++17)

      Returns the filename identified by the generic-format path stripped of its extension.

      Returns the substring from the beginning offilename() up to and not including the last period (.) character, with the following exceptions:

      • If the first character in the filename is a period, that period is ignored (a filename like ".profile" is not treated as an extension).
      • If the filename is one of the special filesystem componentsdot ordot-dot, or if it has no periods, the function returns the entirefilename().

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The stem of the filename identified by the path (i.e. the filename without the final extension).

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Example

      Run this code
      #include <filesystem>#include <iostream>namespace fs= std::filesystem; int main(){for(const fs::path p:{"/foo/bar.txt","/foo/.bar","foo.bar.baz.tar"})std::cout<<"path: "<< p<<", stem: "<< p.stem()<<'\n'; std::cout<<'\n'; for(fs::path p="foo.bar.baz.tar";!p.extension().empty(); p= p.stem())std::cout<<"path: "<< p<<", extension: "<< p.extension()<<'\n';}

      Output:

      path: "/foo/bar.txt", stem: "bar"path: "/foo/.bar", stem: ".bar"path: "foo.bar.baz.tar", stem: "foo.bar.baz" path: "foo.bar.baz.tar", extension: ".tar"path: "foo.bar.baz", extension: ".baz"path: "foo.bar", extension: ".bar"

      [edit]See also

      returns the filename path component
      (public member function)[edit]
      returns the file extension path component
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/path/stem&oldid=158109"

      [8]ページ先頭

      ©2009-2025 Movatter.jp