#include <iostream>
int main()
{
const std::string exclam = "!";
const std::string message = "Hello" + ", world" + exclam;
std::cout << message;
return 0;
}
为什么此代码不起作用?错误返回:无法在C++中添加字符串
error: invalid operands of types `const char[6]' and `const char[8]' to binary `operator+'
在此先感谢!
编辑:
感谢您的所有答案。这是我第一次在这个网站上,我很惊讶于在这么短的时间内详细解释的数量。
关于实际问题。那么这是怎么来的呢:
const std::string hello = "Hello";
const std::string message = hello + ", world" + "!";
是因为“,世界”以及之后的“!”与变量hello(已定义)连接?
为什么不这样做: const std :: string message =“Hello,world”+ exclam; – 2010-02-24 21:32:06
欢迎来到本网站!只是供参考,如果有你喜欢的答案,确保你接受它。你更有可能在未来获得帮助。 – JasCav 2010-02-24 21:44:28