【问题标题】:How to use RGB codes with the fmt library?如何在 fmt 库中使用 RGB 代码?
【发布时间】:2023-01-17 08:36:03
【问题描述】:

我刚刚安装了fmt library,我想知道是否可以使用 RGB 代码而不是颜色名称。例如,而不是,

#include <fmt/color.h>

int main()
{
    std::string cpp = fmt::format(fg(fmt::color::yellow), "C++20");
    fmt::print("{}", cpp);
    return 0;
}
    

是否可以做类似的事情,

#include <fmt/color.h>

int main()
{
    std::string cpp = fmt::format(fg(fmt::color::#FFFF00), "C++20");
    fmt::print("{}", cpp);
    return 0;
}
    

【问题讨论】:

    标签: c++20 rgb fmt


    【解决方案1】:

    在互联网上搜索了几个小时后,我通过反复试验的方法偶然发现了答案。为了使用 RGB 代码而不是颜色名称,请将 color::yellow 替换为 rgb(0xFF, 0xFF, 0x00)rgb(255, 255, 0)

    #include <fmt/color.h>
    
    int main()
    {
        std::string cpp = fmt::format(fg(fmt::rgb(255, 255, 0)), "C++20");
        fmt::print("{}", cpp);
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      • 2010-09-18
      • 2013-05-09
      • 2022-11-13
      • 2020-09-24
      相关资源
      最近更新 更多