Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::filesy...::path::stem(3) C++ Standard Libarystd::filesy...::path::stem(3)

NAME
       std::filesystem::path::stem - std::filesystem::path::stem

Synopsis
	  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 of filename() 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	compo-
       nents dot or
		       dot-dot,	or if it has no	periods, the function  returns
       the entire
		       filename().

Parameters
	  (none)

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

Exceptions
	  May throw implementation-defined exceptions.

Example
       // Run this code

	#include <iostream>
	#include <filesystem>
	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"

See also
	  filename  returns the	filename path component
		    (public member function)
	  extension returns the	file extension path component
		    (public member function)

http://cppreference.com		  2022.07.31	 std::filesy...::path::stem(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::filesystem::path::stem&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help