9

I have seen how useful std::format can be. But every time I try to include it on C++20 it does not work. it is apparently already included in its libraries but it does not appear, and there is no information online. Even cppreference has its example but it does not even run on its online compiler. I attached a snippet from it.

Does anyone of you guys know how to make it work without a super complex importing libraries from GitHub. I mainly work on VisualStudio.

#include <iostream>
#include <format>

int main() {
    std::cout << std::format("Hello {}!\n", "world");
}
main.cpp:2:10: fatal error: No such file or directory
    2 | #include <format>
      |          ^~~~~~~~
compilation terminated.
vitaut
  • 49,672
  • 25
  • 199
  • 336
Andres
  • 161
  • 1
  • 7

1 Answers1

10

As of July 2020 none of the standard library implementations provide std::format. Until they do you can use the {fmt} library std::format is based on:

#include <iostream>
#include <fmt/core.h>

int main() {
  std::cout << fmt::format("Hello {}!\n", "world");
}

godbolt

vitaut
  • 49,672
  • 25
  • 199
  • 336