jac*_*nad 10 c++ concatenation std
可能重复:
如何在一行上连接多个C++字符串?
根据这个,使用operator +连接C++ std :: string.为什么这个代码呢
using namespace std;
string sql = "create table m_table(" +
"path TEXT," +
"quality REAL," +
"found INTEGER);";
Run Code Online (Sandbox Code Playgroud)
导致此错误?
类型'const char [22]'和'const char [17]'到二进制'operator +'的无效操作数
Mic*_*ker 14
克里斯说的是什么,但在这种特殊情况下,你可以做到
string sql = "create table m_table("
"path TEXT,"
"quality REAL,"
"found INTEGER);";
Run Code Online (Sandbox Code Playgroud)
这将在编译时连接字符串.
chr*_*ris 12
您需要将其显式转换为字符串以匹配参数列表:
string sql = std::string("create table m_table(") +
"path TEXT," +
"quality REAL," +
"found INTEGER);";
Run Code Online (Sandbox Code Playgroud)
现在第一个是与a匹配的字符串const char[N],它匹配其中一个operator+重载并返回一个new std::string,用于重复其余的过程.