我只是在审查我的C++。我试图做到这一点:cout和字符串连接
#include <iostream>
using std::cout;
using std::endl;
void printStuff(int x);
int main() {
printStuff(10);
return 0;
}
void printStuff(int x) {
cout << "My favorite number is " + x << endl;
}
该问题发生在printStuff
函数。当我运行它时,输出中将省略“我的最爱号码”中的前10个字符。输出是“电子号码是”。这个数字甚至没有出现。
解决这个问题的方法是做
void printStuff(int x) {
cout << "My favorite number is " << x << endl;
}
我想知道什么计算机/编译器做幕后。