我正在尝试创建一个指向文件的字符串,但出现此错误:
.../testApp.cpp:75: error: invalid operands of types 'const char*' and 'const char [5]' to binary 'operator+'
这是有问题的行:
string path = "images/" + i + ".png";
这似乎是一个相当简单的问题,但却让我感到困惑。我还包含了字符串标题:
#include <string>
using namespace std
最佳答案
或boost::format
:
std::string str = (boost::format("images/%d.png") % i).str();
boost::format(FORMATTED_STIRNG) % .. %.. %..
用于格式化字符串处理,参见 wiki .此函数返回一个特殊的提升格式,您需要使用其 .str()
成员函数将其转换为 std::string。
关于c++ - 连接字符串时出错 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10800104/