【发布时间】:2021-02-21 14:35:06
【问题描述】:
这是我在 StackOverflow 上的第一篇文章!我的 Intro C++ 课程的项目有问题。我在 for 循环中调用时收到 E0349 错误,“没有运算符与这些操作数匹配”。我在这里查看了类似的问题,但没有找到解决方案。如果我的格式有任何错误或不太了解,我深表歉意。这是我的第一堂编程课。
我的代码:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void disp2xInt(int num);
int main() {
// Do "Press any key to continue..." on exit
atexit([] {system("pause"); });
// Print out your name and course
cout << "Jacob" << endl;
cout << "ELET115N" << endl << endl;
for (int i = 0; i < 5; i++) {
cout << disp2xInt(i) << "\n";
cout << "Hello world!!!\n";
}
disp2xInt(9);
return 0;
}
void disp2xInt(int n) {
cout << "2 x " << n;
cout << " = " << n * 2;
cout << endl;
}
【问题讨论】:
-
当
disp2xInt返回void时,您希望cout在cout << disp2xInt(i) << "\n";中打印什么?只需调用它disp2xInt(i)。注意:我有信心,肯定有重复的,因为我每周都会看到这样的问题,但我懒得去找它:/
标签: c++ function loops error-handling