一、头文件
#include"boost/format.hpp"
二、使用步骤
占位符
boost::format fmt( "%1% \n %2% \n %3% " ) %"first"%"second"%"third";
%X%表示占位符,%1%就是第一个占位符,%2%就是第二个,后面类推,再后面的%"xxx"就对应着每个占位符,也就是说如果我们写成:
std::cout<<boost::format("%2% \n %1% \n %3%" )%"first"%"second"%"third";
输出结果:
second
first
third
当然我们也可以分开写,比如:
boost::format fmt("%2% \n %1% \n %3%" );
fmt %"first";
fmt %"second";
fmt %"third";
批量存储文件路径
//文件路径
-image
|-----1.png
|-----2.png
|-----3.png
|-----4.png
|-----5.png
则图片相对路径为:
//空格为了对齐
./ image / x . png
./ %s / %d . %s
例如:
boost::format fmt("./%s/%d.%s" );
frm % "image" % (i + 1) % "png").str();
还能分开写:
boost::format fmt("./%s/%d.%s" );
frm % "image";
frm % (i + 1);
frm % "png";
我们还可以很方便的把格式化后的实例赋给std::string,如:
string path=fmt.str();