c++ - 连接字符串时出错 (C++)

标签 c++ string

我正在尝试创建一个指向文件的字符串,但出现此错误:

.../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/

相关文章:

C++:让 VS2010 提示 "If"和 "="

c++ - 如何使用 std::vector<std::mutex> 之类的东西?

c++ - 如何让 g++ 在终端中显示执行时间?

string - Nodejs中使用zlib对数据进行压缩和解压

string - 戈朗 : print string array in an unique way

java - 字符串分割模式java

android - 收听和接收特定的短信?

c++ - 完美的正方形和完美的立方体

尝试抛出异常时出现c++模板化函数错误

r - 将串联列拆分到相应的列位置