c++ - 在 fmt 中强制对 std::string 进行 UTF-8 处理

标签 c++ fmt

在我的 C++17 项目中,我有一个 std::string ,已知它包含 UTF-8 编码数据。有没有办法强制 fmt 将其数据视为 UTF-8,以便按预期工作?

fmt::print("{:-^11}", "あいう");
// should print "----あいう----", currently prints "-あいう-"

最佳答案

{fmt} 中的 UTF-8 处理最近得到了改进,您的示例现在可以与 master 分支一起使用:

#include <fmt/core.h>

int main() {
  fmt::print("{:-^11}", "あいう");
}

打印

----あいう----

关于c++ - 在 fmt 中强制对 std::string 进行 UTF-8 处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60600550/

相关文章:

c++ - WINAPI GetMessage HWND

c++ - 强制 format_to_n 使用终止零

c++ - 为什么用 brew 安装 fmt 和 gcc 编译器后找不到 fmt 库?

C++ 保留对象列表并通过另一个函数调用构造函数

c++ - fclose() 的 free()/delete/delete[]/realloc() 无效?

c++ - 尝试使用ostream <<运算符对象时,与{fmt} 6.2.1-3 + clang 10.0.0的链接问题

python - Python 中 % 或 .format 运算符的 C++ 等价物是什么?

Visual Studio 中的 C++20 支持

c++ - 在 Windows 中通过 RPC 发送 UDT

c++ - 按位与函数在 C++ 中返回 bool