std::ios_base::getloc
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::ios_base
Member functions
Formatting
Locales
ios_base::getloc
Internal extensible array
Miscellaneous
Member classes
Member types
std::locale getloc() const;
Returns the current locale associated with the stream.
[edit] Parameters
(none)
[edit] Return value
The locale object associated with the stream.
[edit] Example
The output shown was obtained using the clang compiler.
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秒
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 47 | C++98 | the return value was misspecified as the return value of imbue()
|
corrected |