4

我已经看到 std::format 有多么有用。但是每次我尝试将它包含在 C++20 中时它都不起作用。它显然已经包含在它的库中,但它没有出现,也没有在线信息。甚至 cppreference 也有它的示例,但它甚至不能在其在线编译器上运行。我附上了其中的一个片段。

你们中有人知道如何在没有从 GitHub 导入库的超级复杂的情况下使其工作。我主要在 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.
4

1 回答 1

6

截至 2020 年 7 月,没有一个标准库实现提供std::format. 在他们这样做之前,您可以使用基于以下的 {fmt} 库 std::format

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

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

神螺栓

于 2020-07-27T15:18:55.030 回答