C++ 11相当于Boost.Format

Chr*_*ord 18 boost boost-format c++11

像C++ 11标准中的Boost.Format一样吗?我已经能够避免使用Boost和更好的C++ 11选项来满足我所有的其他需求.

就此而言,Boost.Format对Python的语法没有任何影响format().这样的事情会更好.

vit*_*aut 16

正如nosid正确指出的那样,C++ 11和C++ 14都没有提供与Boost格式相同的功能.

但是,可选择使用C++ 11功能(如可变参数模板)的fmt库提供了类似Python的format函数的实现:

std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
Run Code Online (Sandbox Code Playgroud)

*printf功能的安全替代品:

fmt::printf("The answer is %d\n", 42);
Run Code Online (Sandbox Code Playgroud)

免责声明:我是这个图书馆的作者


nos*_*sid 8

有一个类似于boost-format的提议.但是,它既不是C++ 11也不是C++ 14的一部分,也没有添加任何与字符串格式相关的内容.

在这里您可以找到最新的提案.与boost-format相比,它基于可变参数模板.