TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25757 6
Printing UTF-8 strings since C++23

C++23 provides significant better support to print UTF-8 strings.

For example:

std::string s = "K\u00F6ln: 100\u20AC"; // string ö and €
 
std::println("{}", s);        // prints "Köln 100€"

// print hexadecimal code units (bytes of the UTF-8 string):
std::vector<char> v{std::from_range, s};
std::println("{:n:X}", v);    // prints 4B, C3, B6, 6C, 6E, 3A, 20, 31, 30, 30, E2, 82, AC

// new format specifier to interpret array of char as string:
std::println("{:?s}", v);     // prints "Köln 100€"

This even works fine on Windows platforms (using I/O streams or std::format() might print garbage with a native Windows compiler on a native Windows platform).

See sections 3.2.3 and 4.3.3 of [www.cppstd23.com](http://www.cppstd23.com) .

https://redd.it/1wlg83l
@r_cpp
Cppstd23 Nicolai M. Josuttis: C++23 - The Complete Guide Programming with C++23 by Nicolai Josuttis
More from @r_cpp
  1. Oct 5, 2026std::call_once vs. std::async https://devblogs.microsoft.com/oldnewthing/20260917-00/?p=11…
  2. Oct 4, 2026Magic statics vs. std::call_once https://devblogs.microsoft.com/oldnewthing/20260916-00/?p…
  3. Oct 4, 2026At cppcon WG21 had a whiteboard asking attendees what they would like to have in C++29 som…
  4. Oct 4, 2026Stateful compile-time functions In section 9.1.2 of this book[1] it mentions that C++23 al…
  5. Oct 4, 2026fastgltf: modern C++17 glTF 2.0 library focused on speed https://github.com/spnda/fastgltf…
  6. Oct 4, 2026Shipping Complex Qt Applications in the Browser with emscripten-forge https://emscripten-f…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →