我知道使用%s格式说明符,std::string这样会导致未定义的行为:
std::string myString = "test";
printf("%s", myString);
std::string但是使用相同的说明符和 a with是否可以节省boost::format?
#include <boost/format.hpp>
int main()
{
std::string myString = "test";
boost::format fmt("%s");
fmt % myString;
std::cout << fmt.str();
return 0;
}
%s指定一个 (const) char*,但我提供一个std::string. 这也会导致UB吗?