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

标签 python c++ python-3.x fmt

我是 C++ 的新手,我正在编写一个程序,该程序需要一个运算符来执行与 Python % 运算符相同的操作。 C++ 中是否有任何等效项?

最佳答案

C++20 std::format 图书馆服务于此目的:

#include <iostream>
#include <format>
 
int main() {
    std::cout << std::format("Hello {}!\n", "world");
}

有关如何使用它的更多信息和指南,请参阅:

然而,<format>在某些标准库实现中尚未提供 — 请参阅 C++20 library features .在此期间,您可以使用 https://github.com/fmtlib/fmt ,这是等效的(也是 <format> 的灵感来源)。

关于python - Python 中 % 或 .format 运算符的 C++ 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63105833/

相关文章:

python - 睡衣骨架意义

c++ - 如何使用 Ghostscript 自动安装 RedMon

c++如何从 vector 中找到总和为给定数字的元素的最小数量

python - 命令帮助(通过 -h) 其中 `argparse` 是范围检查输入端口号

python - 我有 2 个列表,我想合并它们,答案应该如下所示

python - 更改父级继承的python类的方法

python - 为什么 Pygame 的 KMOD_SHIFT 未解析并使我的代码崩溃?

python - python用nginx+uwsgi写登录的方法

c++ - 使用构造函数语法初始化引用

python - 如何使用 NumPy 从列表创建多维数组?