{fmt}中的UTF-8处理最近得到了改进,您的示例现在可以使用
在我的C++17项目中,我有一个std::字符串,已知它包含UTF-8编码的数据。是否有任何方法可以强制fmt将其数据处理为UTF-8,以便按预期工作?
fmt::print("{:-^11}", "あいう");
// should print "----あいう----", currently prints "-あいう-"
master
分支:
#include <fmt/core.h>
int main() {
fmt::print("{:-^11}", "あいう");
}
打印
----あいう----
将字段宽度作为下一个参数并自己计算:
#include <fmt/format.h>
#include <cstring>
int main() {
fmt::print("{:-^{}}", "あいう", 8 + std::strlen("あいう"));
}