In most recent MSVC 19.40 (Visual Studio 2022 17.10 preview 2), calling println() with whar_t and std:wstring, or print with std:wstring, will result in compiler errors
[Edit] in c++20 mode when you also include "fmt\std.h", <iostream> or <ostream>.
#include <fmt/format.h>
#include <fmt/xchar.h>
//Compile error in MSVC 19.40 (VS 2022 17.10 preview) with /std:c++20 and one of the following headers
#include "fmt\std.h"
#include <ostream>
#include <iostream>
int main() {
fmt::println(L"Error: φαρδιές χορδές");
fmt::println(L"Error: {}", L"φαρδιές χορδές");
fmt::print(L"{}", format(L"Errror: {}", L"φαρδιές χορδές") );
}
fmt\xchar.h(271,41): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
fmt\xchar.h(271,10): error C2661: 'fmt::v10::vprint': no overloaded function takes 1 arguments
fmt\xchar.h(139,47): error C2672: 'fmt::v10::make_wformat_args': no matching overloaded function found
fmt\xchar.h(139,10): error C2661: 'fmt::v10::vformat': no overloaded function takes 1 arguments
It worked fine in previous versions like MSVC 19.38:
https://godbolt.org/z/cqoz8esjn
Now print() with whar_t kind of works, but it will raise runtime exceptions for any non-ASCII symbols by default, unless I call _setmode to enable one of Unicode text translation modes in the CRT - then it works fine and prints correct non-ASCII symbols; in binary mode, it prints some mojibake.
print() and println() seem to work fine with UTF-8 strings - although displaying correct non-ASCII symbols requires /utf-8 compiler option, otherwise these will show as question marks or a different kind of mojibake.
I'm back to using wprintf_s() as I need to print localized COM error messages supplied by Windows API, and std::print only supports UTF-8 but not wchar_t.
In most recent MSVC 19.40 (Visual Studio 2022 17.10 preview 2), calling
println()withwhar_tandstd:wstring, orprintwithstd:wstring, will result in compiler errors[Edit] in c++20 mode when you also include
"fmt\std.h",<iostream>or<ostream>.It worked fine in previous versions like MSVC 19.38:
https://godbolt.org/z/cqoz8esjn
Now
print()withwhar_tkind of works, but it will raise runtime exceptions for any non-ASCII symbols by default, unless I call _setmode to enable one of Unicode text translation modes in the CRT - then it works fine and prints correct non-ASCII symbols; in binary mode, it prints some mojibake.print()andprintln()seem to work fine with UTF-8 strings - although displaying correct non-ASCII symbols requires/utf-8compiler option, otherwise these will show as question marks or a different kind of mojibake.I'm back to using
wprintf_s()as I need to print localized COM error messages supplied by Windows API, andstd::printonly supports UTF-8 but notwchar_t.