The header file will not compile into my main test program. Why would this be the case. I have looked on line but found no simple reason why this would be the case. I have tried a couple of #ifndef
, and #define
and am still not sure as to why the file will not include into my test program.
Below are the error message that I receive when I try and compile my test program. This has to do with the header file but I am not really sure how to fix this simple problem. Strangely i have used C++ before and did not remember having this trouble with the header file.
error:
Error 1 error C2015: too many characters in constant c:\users\itpr13266\desktop\c++\testproject\testproject\testproject.cpp 10 1 TestProject
Error 2 error C2006: '#include' : expected a filename, found 'constant' c:\users\itpr13266\desktop\c++\testproject\testproject\testproject.cpp 10 1 TestProject
Error 3 error C1083: Cannot open include file: '': No such file or directory c:\users\itpr13266\desktop\c++\testproject\testproject\testproject.cpp 10 1 TestProject
code
#include "stdafx.h"
#include "iostream"
#include <iostream>
#include <fstream>
#include <math.h>
#include <iostream>
#ifndef MYDATESTRUCTURES_H
#define MYDATESTRUCTURES_H
#include'myDataStructures.h' <-- name of my include file
#endif
using namespace std;
#define MY_NAME "Alex"
void f(int);
void DoSome(int, char);
enum color { red, green, blue };
enum color2 { r, g=5, b };
class CVector {
public:
int x,y;
CVector () {}
CVector (int a, int b) : x(a), y(b) {}
void printVector()
{
std::cout << "X--> " << x << std::endl;
std::cout << "Y--> " << y << std::endl;
}
};
CVector operator+ (const CVector& lhs, const CVector& rhs) {
CVector temp;
temp.x = lhs.x + rhs.x;
temp.y = lhs.y + rhs.y;
return temp;
}
template<typename T>
void f(T s)
{
std::cout << s << '\n';
}
template<typename P, typename N>
void DoSome(P a, N b)
{
std::cout << "P--> " << a << '\n';
std::cout << "N--> " << b << '\n';
}
void testMath()
{
int result = ceil(2.3) - cos(.2) + sin(8.0) + abs(3.44);
cos(4.1);
}
void testStorageTypes()
{
int a;
register int b;
extern int c;
static int y;
}
color temp = blue;
color2 temp2 = r;
int _tmain(int argc, _TCHAR* argv[])
{
std::getchar();
return 0;
}
code (header file)
#include <iostream>
int myAdd1(int, int);
int myAdd2(int, int, int, int, int);
struct myFirst1
{
}
struct myFirst2
{
}
int myAdd1(int x, int y)
{
return x + y;
}
int myAdd2(int x, int y, int z, int m, int y)
{
return x + y;
}