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

FreeBSD Manual Pages

  
 
  

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

NAME
       std::filesystem::path::make_preferred	      -		 std::filesys-
       tem::path::make_preferred

Synopsis
	  path&	make_preferred();  (since C++17)

	  Converts all directory separators in the generic-format view of  the
       path to the
	  preferred directory separator.

	  For  example,	 on  Windows,  where \ is the preferred	separator, the
       path foo/bar will
	  be converted to foo\bar.

Parameters
	  (none)

Return value
	  *this

Exceptions
	  May throw implementation-defined exceptions.

Example
	  Windows can use / as a separator, but	prefers	\,  so	make_preferred
       converts	the
	  forward  slashes  to	backslashes. On	the other hand,	POSIX does not
       use \ as	a
	  separator, because backslashes are valid  filename  characters   the
       Windows path on
	  POSIX	 actually  refers  to a	file with the name "a\\b\\c". For this
       reason the
	  "separators" are not converted.

       // Run this code

	#include <filesystem>
	#include <iostream>
	#include <iomanip>

	int main()
	{
	  std::filesystem::path	windows_path{"a\\b\\c"};
	  std::filesystem::path	posix_path{"a/b/c"};
	  std::cout << "Windows	path: "
		    << std::quoted(windows_path.string()) << " -> "
		    << std::quoted(windows_path.make_preferred().string())  <<
       '\n'
		    << "POSIX path: "
		    << std::quoted(posix_path.string())	<< " ->	"
		    <<	 std::quoted(posix_path.make_preferred().string())  <<
       '\n';
	}

Output:
	# on Windows
	Windows	path: "a\\b\\c"	-> "a\\b\\c"
	POSIX path: "a/b/c" -> "a\\b\\c"
	# on POSIX
	Windows	path: "a\\b\\c"	-> "a\\b\\c"
	POSIX path: "a/b/c" -> "a/b/c"

See also
			       alternative directory separator	which  may  be
       used in addition
	  constexpr  value_type	 to  the  portable  /. On Windows, this	is the
       backslash character
	  preferred_separator  \. On POSIX, this is the	same forward  slash  /
       as the portable
	  [static]	       separator
			       (public static member constant)

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

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

home | help