chr*_*ise 10 c++ io formatting fmt
我正在寻找一种快速而简洁的方式来打印一个漂亮的表格格式,正确对齐单元格.
在c ++中是否有一种方便的方法来创建具有一定长度的子串的字符串,如python格式
"{:10}".format("some_string")
Run Code Online (Sandbox Code Playgroud)
vit*_*aut 32
在 C++20 中,您将能够使用std::format它为 C++ 带来类似 Python 的格式:
auto s = std::format("{:10}", "some_string");
Run Code Online (Sandbox Code Playgroud)
在那之前,你可以使用开放源代码{} FMT格式化库,std::format是基于。
免责声明:我是 {fmt} 和 C++20 的作者std::format。
mat*_*ttn 15
试试这个 https://github.com/fmtlib/fmt
fmt::printf("Hello, %s!", "world"); // uses printf format string syntax
std::string s = fmt::format("{0}{1}{0}", "abra", "cad");
Run Code Online (Sandbox Code Playgroud)
小智 6
你在这里有很多选择。例如使用流。
源文件
std::ostringstream stream;
stream << "substring";
std::string new_string = stream.str();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8504 次 |
| 最近记录: |