我试图创建一个指向文件的字符串,并收到此错误:
... / testApp.cpp:75:错误:类型为'const char *'和'const char [5]'的无效操作数为二进制'operator +'
这是有问题的行:
string path = "images/" + i + ".png";
Run Code Online (Sandbox Code Playgroud)
这似乎是一个相当简单的问题,但令我困惑。我还包括了字符串标题:
#include <string>
using namespace std
Run Code Online (Sandbox Code Playgroud)
或boost::format:
std::string str = (boost::format("images/%d.png") % i).str();
Run Code Online (Sandbox Code Playgroud)
boost::format(FORMATTED_STIRNG) % .. %.. %..用于格式化字符串,请参阅wiki。此函数为您提供了一种特殊的增强格式,您需要使用其.str()成员函数将其强制转换为std :: string 。