std::filesy...ke_preferred(3)
β¨ NAME β¨
This is the manual page for std::filesy...ke_preferred(3) from the C++ Standard Libary β yes, βLibaryβ is literally how the header spells it, bestie, and we respect the typo. π
std::filesystem::path::make_preferredβstd::filesystem::path::make_preferred(thatβs the NAME entry, and yes, it is just the function naming itself twice; iconic, no notes).
πΈ Synopsis πΈ
path& make_preferred(); (since C++17)
Okay so hereβs the vibe: it 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. Slay.
π Parameters π
None. Literally (none) β no parameters, no args, zero, zilch. π«Ά
π Return value π
*this β it hands you back *this, periodt. π
π¦ Exceptions π¦
May throw implementation-defined exceptions. Thatβs the whole warning, bestie β implementation-defined means exactly what it says. π
π Example π
// Run this code β like the page says, run it:
#include <filesystem>
#include <iostream>
int main()
{
std::filesystem::path
windows_path("a\\b\\c"),
posix_path("a/b/c");
std::cout
<< "Windows path: "
<< windows_path << " -> "
<< windows_path.make_preferred() << '\n'
<< "POSIX path: "
<< posix_path << " -> "
<< posix_path.make_preferred() << '\n';
}
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. Itβs giving platform differences, fr fr. π
π» 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 π
preferred_separatorβ aconstexpr value_type,[static](public static member constant). Itβs the alternative directory separator which may be used in addition to the portable/. On Windows, this is the backslash character\. On POSIX, this is the same forward slash/as the portable separator. π¦
Source/version: http://cppreference.com, dated 2024.06.10, and the page title is std::filesy...ke_preferred(3) β thatβs the footer, now with a little bow on it πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms