我有一个语法正确且非常简单的应用程序,该应用程序从用户那里获取两个整数,并对它们进行减法和加法运算。但是,当我尝试编译程序时,出现此错误:
Could not find 'C:\Users\MyUsername\source\repos\SimpleCalculator\SimpleCalculator\Debug\SimpleCalculator.obj'. SimpleCalculator.exe was built with /DEBUG:FASTLINK which requires object files for debugging.
这是我的代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
int a, b;
cout << "Welcome." << endl;
cout << "Enter first number: ";
cin >> a;
cout << "Enter second number: ";
cin >> b;
cout << "A+B is: ";
cout << addition(a,b) << endl;
cout << "A-B is: ";
cout << substraction(a,b) << endl;
system("pause");
}
int addition(int a, int b) {
return a + b;
}
int substraction(int a, int b) {
return a - b;
}
仅当我具有功能时才会发生此错误。当我的代码是:
cout << "A+B is: ";
cout << a+b << endl;
没有错误。
最佳答案
您需要在调用函数之前声明函数,因此基本上有2个选项:
在main
之前声明它们:
int addition(int a, int b);
int substraction(int a, int b);
或将它们的整个定义移到
main
前面。
关于c++ - 编译简单的C++应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46155484/