Boost库格式;得到std :: string [英] Boost Library Format; getting std::string
本文介绍了Boost库格式;得到std :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想添加一些我使用boost库格式化的字符串,如下所示:
I want to add some string which I format using the boost library as follows
boost::container::vector<std::string> someStringVector;
someStringVector.push_back(
format("after is x:%f y:%f and before is x:%f y:%f\r\n") %
temp.x %
temp.y %
this->body->GetPosition().x %
this->body->GetPosition().y;
编译器抱怨它不能转换类型,我尝试将.str()附加到返回的格式的末尾,但是它仍然抱怨.
The compiler is complaining that it can't convert types, and I tried appending .str() to the end of what format returns, but it still complained.
我收到的错误消息是:
error C2664: 'void boost::container::vector<T>::push_back(
const std::basic_string<_Elem,_Traits,_Ax> &)' :
cannot convert parameter 1 from
'boost::basic_format<Ch>' to
'const std::basic_string<_Elem,_Traits,_Ax> &'
有人有见识吗?
推荐答案
您需要将格式包装在对boost :: str的调用中,就像这样:
You need to wrap the format in a call to boost::str, like so:
str( format("after is x:%f y:%f and before is x:%f y:%f\r\n")
% temp.x % temp.y % this->body->GetPosition().x % this->body->GetPosition().y)
这篇关于Boost库格式;得到std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文