I keep getting an error with the cpp that asks if I forgot to include stdafx.h, which I have done in the header, the error code is C1010.
The full error reads: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
First I have a header file which defines some basic functions for a calculator. Which accept arguments when called.
#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;
};
Then there's the cpp which simply computes the 2 arguments and returns the answer.
#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;
}
Please explain in simple terms, I'm not very good at coding.
stdafx.h is a precompiled header used by visual studio, you can remove it.
Edit: Turns out this only works if you turn off precompiled headers in visual studio. They are on by default in visual studio.
If you want to keep them on they have to be before any other includes.
So your pre processor directives should be :