std::ostringstream ostr; // include <sstream>
ostr << "targetBox.m_vMax(" << targetBox.m_vMax.x ;
ostr << "," << targetBox.m_vMax.y ;
ostr << "," << targetBox.m_vMax.z ;
ostr << ")";
ostr << "targetBox.m_vMin(" << targetBox.m_vMin.x ;
ostr << "," << targetBox.m_vMin.y ;
ostr << "," << targetBox.m_vMin.z ;
ostr << ")";
ostr << "m_vMax(" << m_vMax.x ;
ostr << "," << m_vMax.y ;
ostr << "," << m_vMax.z ;
ostr << ")";
ostr << "m_vMin(" << m_vMin.x ;
ostr << "," << m_vMin.y ;
ostr << "," << m_vMin.z ;
ostr << ")";
//std::cout << ostr.str().c_str() << std::endl;
std::string s = ostr.str();
Logs::LogsWrite((TCHAR*)s.c_str(),"testCollionTest.txt");
离开了MFC一下子连怎么拼接字符串都不会了,从网上查到了用std::ostringstream可以实现,记录下来。
本文介绍了一种使用C++标准库中的std::ostringstream来高效拼接字符串的方法。通过实例展示了如何将不同类型的变量(如浮点数)转换为字符串,并将其拼接起来。这对于需要频繁生成复杂字符串的应用场景非常有用。
477

被折叠的 条评论
为什么被折叠?



