Questions tagged [fmt]

The {fmt} formatting library and the C++ text formatting and output facility (C++20 `std::format` and C++23 `std::print`).

{fmt} is an open source formatting library for . It is similar in functionality to and sprintf. The formatting facility defined in the <format> header is based on it and provides a subset of {fmt}'s functionality.

259 questions
9
votes
1 answer

can't include std::format

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…
Andres
  • 161
  • 1
  • 7
9
votes
3 answers

How to use the fmt library without getting "Undefined symbols for architecture x86_64"

I'm trying to use the fmt (https://github.com/fmtlib/fmt) formatting header library in my c++ project. I've added the path to the core header file at the top of my main file like so: #include "../third_party/fmt/core.h" but when I try to call any…
CoderCal
  • 149
  • 1
  • 1
  • 9
8
votes
1 answer

How to use std::format to format all derived class of the same base class?

I have lots of classes derived from the same base class, and I'm trying to avoid writing a formatter for all derived classes. I tried to only implement the std::formatter for the base class, but passing a derived class object/reference to…
8
votes
1 answer

Is there a way to suppress the fmt range formatter for a user defined class?

I have a simple class that has a tostring() method: class MyClass { public: std::string tostring() const; static iterator begin(); static iterator end(); }; Although I'm using the fmt library now, this code is ported from code that…
user1806566
  • 1,078
  • 6
  • 18
8
votes
3 answers

C++20 support in Visual Studio

I'm wanting to use std::format but Visual Studio says the std namespace has no member format. It appears this is new for C++20. Is there a way to make it available?
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
7
votes
1 answer

Code using fmt::format breaks after Visual Studio 2022 Update 17.4

I am using fmt::format from the fmtlib extensively. After updating Visual Studio 2022 from 17.3.5 to 17.4.0 I have a problem in Release Builds with Code like the following: const std::string s1 = format("{}.{}", "abc", "test" ); While s1 and…
Stefan F.
  • 141
  • 2
7
votes
1 answer

Prevent fmt from printing function pointers

I have a following buggy program. Logic is nonsense, it is just a toy example. #include #include #include #include template constexpr bool size_is_4(){ return sizeof(T)==4; } int…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
7
votes
3 answers

How come the fmt library is not header-only?

I know it is possible to use the fmt formatting library in header-only mode: How to use fmt library in the header-only mode? but - why isn't it just header-only, period? That is, what's the benefit of using it in non-header-only mode?
einpoklum
  • 118,144
  • 57
  • 340
  • 684
7
votes
1 answer

Using {fmt} & source_location to create variadic-template-based logging function

I'd like to create a simple log function in C++ which prepend the code location to the log message. I'd like to avoid macros overall as well as the usage of __FILE__ & __LINE__. Note that the format string is always a compile-time string, and I'd…
galah92
  • 3,621
  • 2
  • 29
  • 55
7
votes
2 answers

Printing using {fmt} library

Can I print an object of the C++ class using fmt library? fmt::print("The object is {}.", obj);
sadig
  • 431
  • 1
  • 4
  • 9
7
votes
1 answer

Custom {fmt} formatting function with compile time format string checking

I've got my own logging functions. I want to use libfmt to format the log parameters, eg: log_error("Error on read: {}", errMsg); However compile time format string checking seems to only work if I call the print/format functions directly, not if I…
Mart
  • 1,278
  • 12
  • 12
6
votes
1 answer

CMake add fmt library

I have a CMake project, with following structure: cmake_minimum_required(VERSION 3.11) project(ReadGraph) # Download and unpack googletest at configure time configure_file(CMakeLists.txt.in…
Artur Laskowski
  • 312
  • 4
  • 13
6
votes
1 answer

Using fmtlib, zero padded numerical value are shorter when the value is negative, can I adapt this behaviour?

I am using fmtlib to format strings and numeric values but I have problem with negative integers. When I pad the value with zeroes, I expect a consistent number of zero no matter the sign of the value. For instance, using a padding of 4, I would…
jeromes
  • 497
  • 5
  • 17
6
votes
1 answer

How to test if console supports ANSI color codes?

I use fmt based logger with optionally color prints - which relies on ANSI color commands. Unfortunately on Windows 10 it is disabled by default. I know how to enable it but I still want to find out how to test whether the console supports ANSI…
ALX23z
  • 4,456
  • 1
  • 11
  • 18
6
votes
1 answer

I can't use fmt library headers on c++

I've downloaded, built and added to the project the {fmt} 6.2.1 library on c++. I'm using Windows. Problem is, the headers are recognized(Code:Blocks give me the auto-completion for them) but any function I try to use results in errors. For example…
David
  • 123
  • 1
  • 10
1
2
3
17 18