I am looking a lecture for CppCon and the teacher uses std::print. However, I am not…
- User
I am looking a lecture for CppCon and the teacher uses std::print. However, I am not able to replicate this code because I do not know which library include.
- Assistant
As of my last update,
std::printis not part of the standard C++ library. It's possible that the speaker in the CppCon lecture was referring to a custom utility or function that was defined outside of the standard library, or it could be part of an experimental feature or proposal.In standard C++, the typical way to print to the console is to use
std::coutfrom the iostream library. Here's a simple example:cpp#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }If
std::printis something newly proposed or introduced in an experimental library or toolset specific to the lecture you're watching, you might want to check the lecture notes, supplementary materials, or any provided project files for more context.Alternatively, C++20 and later versions introduce the
<format>library, where you can do formatted output like this:cpp - User
Accessing to the code, he is including fmt/ranges.h and in the code the call is fmt::print . Do you something about it?
- Assistant
Yes, the
fmtlibrary is a popular open-source formatting library for C++. It provides features for formatting strings and printing them to various outputs. Thefmt::printfunction is part of this library and is used for printing formatted output conveniently, similar to Python's formatted string literals or C'sprintf.The
ranges.hheader infmtextends the library's capabilities to work with C++ ranges, allowing you to format and print range-based data structures more naturally.Here's a brief example of how you might use
fmt::print:cpp