我想添加一些我使用boost库格式化的字符串,如下所示
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()附加到格式返回的结尾,但仍然抱怨.
我得到的错误信息是:
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,_Ax> &'
任何人都有一些洞察力
解决方法
您需要在调用boost :: str中包装格式,就像这样:
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)