0

I'm trying to use C++ std::format in Visual Studio 2022.

I've selected C++ Language Standard: "Preview - Features from the Latest C++ Working Draft (/std:c++latest)" after initially trying "ISO C++20 Standard (/std:c++20)"

The post below seems to indicate that selecting the Preview standard should work, but I don't have enough status to comment on that post directly. C++20 support in Visual Studio

Should std::format work in VS2022 with the #include statement?

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
jeff28273
  • 422
  • 5
  • 11

1 Answers1

3

Should std::format work in VS2022 with the #include statement?

Yes, but it currently only works in /std:c++latest (Preview) mode which you can set in Project\Properties\Configuration\Properties\C++ Language Standard.

Demo

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • Thanks for you code snippet and explanation. I was able to get your demo code working and my system recognizes the std::format code when creating a new example. One complication I currently have is that I have some legacy code VS2019 C++ that does not recognize std::format even when /std:c++latest (Preview) is selected. I'll dig into this more to see why the demo code works but my legacy code does not. – jeff28273 Feb 20 '22 at 15:28
  • I found that I was targeting Release, but I was changing the C++ version in Debug. Changing the release C++ version solved the initial issue. Thanks again – jeff28273 Feb 20 '22 at 15:42
  • @jeff28273 Oh, great. I've made that mistake myself a couple of times :-) You're welcome! – Ted Lyngmo Feb 20 '22 at 15:48