forked from OctaForge/libostd
example of locale specific numeric formatting
This commit is contained in:
parent
2f4f9dd440
commit
dc1d3aa373
|
@ -1,4 +1,5 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <clocale>
|
||||||
|
|
||||||
#include <ostd/algorithm.hh>
|
#include <ostd/algorithm.hh>
|
||||||
#include <ostd/vector.hh>
|
#include <ostd/vector.hh>
|
||||||
|
@ -110,4 +111,16 @@ int main() {
|
||||||
auto s = appender_range<std::string>{};
|
auto s = appender_range<std::string>{};
|
||||||
format(s, "hello %s", "world");
|
format(s, "hello %s", "world");
|
||||||
writeln(s.get());
|
writeln(s.get());
|
||||||
|
|
||||||
|
/* locale specific formatting */
|
||||||
|
ostd::writefln(
|
||||||
|
"C locale: \"%d\", \"%f\", \"%X\"",
|
||||||
|
123456789, 12345.6789123, 0x123456789ABCDEF
|
||||||
|
);
|
||||||
|
std::setlocale(LC_ALL, "");
|
||||||
|
ostd::out.imbue(std::locale{std::setlocale(LC_NUMERIC, nullptr)});
|
||||||
|
ostd::writefln(
|
||||||
|
"%s locale: \"%d\", \"%f\", \"%X\"", ostd::out.getloc().name(),
|
||||||
|
123456789, 12345.6789123, 0x123456789ABCDEF
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue