非常详细:
https://hackingcpp.com/cpp/libs/fmt.html#integers
包括:
前端补齐空格或者其他字符进行对齐,
是否居中,
二进制显示,
长数字加都好分隔符,
输出到文件,
对字符串进行截断(只截取字符串的前几个字符),
浮点数的格式化输出
浮点数的精度,以及四舍五入
用fmt::ptr打印指针
打印range:vector,pair、tuple、set和map
打印时间
内存管理:分解字符串?
#include <fmt/format.h>
int main ()
{
double const d = 123.45678;
fmt::memory_buffer buf;
format_to(std::back_inserter(buf), "{:e}", d);
auto ptrToFormattedData = buf.data();
auto sizeOfFormattedData = buf.size();
fmt::print("{}\n", ptrToFormattedData);
fmt::print("{}\n", sizeOfFormattedData);
auto str = to_string(buf); // std::string str = "1.234568e+02";
fmt::print("{}\n", str);
}
//
/
#include <fmt/ranges.h>
#include <iterator>
#include <vector>
int main ()
{
double const d = 123.45678;
std::vector<char> vc;
fmt::format_to(std::back_inserter(vc), "{:e}", d);
// vc = {'1','.','2','3','4','5','6','8','e','+','0','2'}
fmt::print("{}\n", vc);
fmt::print("{}\n", vc.size());
}