std::filesy...ath::native,(3)
π std::filesystem::path::c_str & native π
okay so bestie, welcome to the <pink>std::filesy...ath::native,(3)</pink> page from the C++ Standard Libary (yes, thatβs the headerβs spelling, not a typo from me π). This is the manual for std::filesystem::path::c_str and std::filesystem::path::native, and itβs literally about accessing the native path name as a character string. periodt. π«Ά
β¨ NAME β¨
std::filesystem::path::c_str,std::filesystem::path::native, - std::filesystem::path::c_str,std::filesystem::path::native,
Thatβs the NAME line exactly, repeated like itβs main character energy. Itβs giving βwe are the c_str and native members of std::filesystem::pathβ π
.
π¦ Synopsis π¦
const value_type* c_str() const noexcept; (1) (since C++17)
const string_type& native() const noexcept; (2) (since C++17)
operator string_type() const; (3) (since C++17)
Accesses the native path name as a character string. Iconic.
- Equivalent to
native().c_str(). - Returns the native-format representation of the pathname by reference.
- Returns the native-format representation of the pathname by value.
π Parameters π
(none) β literally nothing to pass, bestie. π
π Return value π
The native string representation of the pathname, using native syntax, native character type, and native character encoding. This string is suitable for use with OS APIs. π₯
πΈ Notes πΈ
The conversion function (3) is provided so that APIs that accept std::basic_string file names can use pathnames with no changes to code. No cap, thatβs the whole note. β¨
π§ Example π§
okay bestie, the example literally says // Run this code, so hereβs the code copied exactly with all its original energy:
#include <cstdio>
#ifdef _MSC_VER
#include <fcntl.h>
#include <io.h>
#else
#include <clocale>
#include <locale>
#endif
#include <filesystem>
#include <fstream>
int main()
{
#ifdef _MSC_VER
_setmode(_fileno(stderr), _O_WTEXT);
#else
std::setlocale(LC_ALL, "");
std::locale::global(std::locale(""));
#endif
std::filesystem::path p(u8"θ¦γγͺγ.txt");
std::ofstream(p) << "File contents"; // Prior to LWG2676 uses
operator string_type()
// on MSVC, where string_type
is wstring, only
// works due to non-standard
extension.
// Post-LWG2676 uses new
fstream constructors
// Native string representation can be used with OS-specific APIs
#ifdef _MSC_VER
if (std::FILE* f = _wfopen(p.c_str(), L"r"))
#else
if (std::FILE* f = std::fopen(p.c_str(), "r"))
#endif
{
for (int ch; (ch = fgetc(f)) != EOF; std::putchar(ch))
{}
std::fclose(f);
}
std::filesystem::remove(p);
}
π Possible output π
File contents
π See also π
stringwstringβ returns the path in native pathname format converted to a stringu8stringβ (public member function)u16stringu32stringgeneric_stringgeneric_wstringβ returns the path in generic pathname format converted to a stringgeneric_u8stringβ (public member function)generic_u16stringgeneric_u32string
bestie, these are the see-also besties, all present and accounted for. π
π source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::filesy...ath::native,(3) β okay bye bestie, go slay those native paths! π
π¦ 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