std::filesy...ath::native,(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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.

  1. Equivalent to native().c_str().
  2. Returns the native-format representation of the pathname by reference.
  3. 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 πŸ‘‘

  • string
  • wstring β€” returns the path in native pathname format converted to a string
  • u8string β€” (public member function)
  • u16string
  • u32string
  • generic_string
  • generic_wstring β€” returns the path in generic pathname format converted to a string
  • generic_u8string β€” (public member function)
  • generic_u16string
  • generic_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