我不断收到 cpp 错误,询问我是否忘记包含我在标题中完成的 stdafx.h,错误代码是 C1010。
完整的错误为:在寻找预编译头文件时意外结束文件。您是否忘记将 '#include "stdafx.h"' 添加到您的源代码中?
首先,我有一个头文件,它定义了计算器的一些基本功能。调用时接受参数。
#pragma once
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;
class Functions
{
public:
Functions() {};
float add(float a, float b);
float subtract(float a, float b);
float multiply(float a, float b);
float divide(float a, float b);
private:
float answer;
};
然后是 cpp,它简单地计算 2 个参数并返回答案。
#pragma once
#include "Functions.h"
float Functions::add(float a, float b)
{
answer = a + b;
return answer;
}
float Functions::subtract(float a, float b)
{
answer = a - b;
return answer;
}
float Functions::multiply(float a, float b)
{
answer = a * b;
return answer;
}
float Functions::divide(float a, float b)
{
answer = a / b;
return answer;
}
请简单解释一下,我不是很擅长编码。