boost::format 以及 for 新特性

一、boost::format

boost::format类提供了类似C语言里'printf'功能的格式化输出能力,功能更强大。

要先include <boost/format.hpp>这个头文件。

1、一般格式

cout << boost::format("%2.3f, %d")  %1.23456  %12; 
printf( "%2.3f, %d\n" , 1.23456, 12 );
/*
1.234,12
*/

2、占位符

%X%表示占位符,%1%就是第一个占位符,%2%就是第二个。

cout<<boost::format("%2% \n %1% \n %3%" )  %"first"  %"second"  %"third";
/*
second
first
third
*/

3、boost::format对象的操作 

# 对象的形式
 boost::format fmt("%2% \n %1% \n %3%" );
 fmt %"first";
 fmt %"second";
 fmt %"third";
cout<<fmt<<endl;

4、转成字符串

1、string s=fmt.str();
2、string s2=boost::str(fmt);
/*
second,first,third
*/

总结:

方式1
cout<<boost::format("%s") % "输出内容" <<endl;
方式2
boost::format fmt("%s");
fmt % "输出内容";
string s=fmt.str();
cout<<s<<endl;
方式3
string s;
s=str(boost::format("%s") % "输出内容");
cout<<s <<endl;

解析点云拼接boost::format 部分

# 拼接出格式化的图片文件名./color/1.png
# ./当前目录  ../父目录  /根目录
vector<cv::Mat> colorimages, depthimages;
vector<Eigen::Isometry3d,Eigen::aligned_allocator<Eigen::Isometry3d>> pose;

boost::format fmt("./s/d./s");
colorimages.push_back(cv::imread((fmt%"color" %"(i+1)" %"png").str()));//str()装字符串
depthimages.push_back(cv::imread((fmt%"depth" % (i+1) % "pgm").str(), -1));//使用-1读取原图




二、for 在C++11的新特性

遍历容器提供了很大的便利,再也不用写那么长的for循环了

1、遍历字符串

string str="hello,world";
for(auto ch:str)
{
      cout<<  ch  <<endl;
}

2、遍历数组

int arr[]={1,2,3,4};
for(auto ch:arr)
{
    cout<< ch <<endl;
}

3、遍历stl容器

# 返回引用,修改容器内容。
vector <string> str={"i","like","google"};
for(auto& ch:str)
{
     ch="C++";
}

解析点云拼接for 部分

# fin读取txt中参数
ifstream fin("./pose.txt");
if (!fin)
	{
		cerr << "请在有pose.txt的目录下运行此程序" << endl;
		return 1;
	}

# 遍历修改数组data的值
double data[7]={0};
for(auto& d:data)
fin>>d;

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值