gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:04:53 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com