我正在尝试将文字与整数连接起来。
问题是当使用 + 运算符将文字与整数连接时,它告诉我“错误:'const char*' 和 'const char [17]' 类型的无效操作数到二进制 'operator+
'".
这是相关代码:
if ( ( A == 0 ) | ( B == 0 ) ) {
cout << "Sorry, gcd(" + A + ',' + B + ") is undefined.\n";
return 0;
}
最佳答案
这里不用拼接,让cout
为您完成所有繁重的工作——它 <<
运算符(operator)可以处理 int
毕竟!
cout << "Sorry, gcd(" << A << ',' << B << ") is undefined.\n";
关于C++ 如何连接文字和整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49805507/