std::ios_base::getloc(3)

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

std::ios_base::getloc(3) πŸ’…

okay so this page is from the C++ Standard Libary manual β€” yes, Libary, that's the spelling in the header, don't come for me πŸ’€. It's all about std::ios_base::getloc, aka the little member function that tells you which locale your stream is currently vibing with. very locale-core, no cap πŸŽ€


🌸 NAME 🌸

std::ios_base::getloc β€” std::ios_base::getloc

✨ Synopsis ✨

std::locale getloc() const;

Returns the current locale associated with the stream. that's the whole job, bestie ✨

πŸŽ€ Parameters πŸŽ€

  • (none) β€” literally no parameters. she takes nothing, she gives locale. iconic 🫢

πŸ’– Return value πŸ’–

The locale object associated with the stream. that's the return value, periodt πŸ’–

πŸ¦‹ Example πŸ¦‹

The output shown was obtained using the clang compiler. (compiler lore, iykyk πŸ”₯)

       // Run this code

        #include <codecvt>
        #include <ctime>
        #include <iomanip>
        #include <iostream>

        int main()
        {
            std::wbuffer_convert<std::codecvt_utf8<wchar_t>>
       conv(std::cout.rdbuf());
            std::wostream out(&conv);

            out.imbue(std::locale(out.getloc(),
                                  new
       std::time_put_byname<wchar_t>("ja_JP.utf8")));

            std::time_t t = std::time(nullptr);
            out << std::put_time(std::localtime(&t), L"%A %c") << '\n';
        }

⭐ Possible output ⭐

        ζœ¨ζ›œζ—₯ 2023εΉ΄10月05ζ—₯ 19ζ™‚47εˆ†58η§’

πŸ’€ Defect reports πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • DR: LWG 47 β€” Applied to: C++98 β€” Behavior as published: the return value was misspecified as the return value of imbue() β€” Correct behavior: corrected

πŸ‘‘ See also πŸ‘‘

  • imbue β€” sets locale (public member function)

shoutout to http://cppreference.com for the source, version/date 2024.06.10, page std::ios_base::getloc(3) β€” bye bestie, go get that locale πŸ’–βœ¨

πŸ“¦ where this page comes from