헤더 파일이 내 주요 테스트 프로그램으로 컴파일되지 않습니다. 왜 이것이 그럴까요? 나는 줄을 서서 보았지만 이것이 왜 그런지에 대한 간단한 이유를 발견하지 못했습니다. #ifndef
및 #define
두 개를 시도했지만 파일이 내 테스트 프로그램에 포함되지 않는 이유는 확실하지 않습니다.#include 파일이 컴파일되지 않는 이유는 무엇입니까?
다음은 테스트 프로그램을 컴파일하고 컴파일 할 때 나타나는 오류 메시지입니다. 이것은 헤더 파일과 관련이 있지만이 간단한 문제를 해결하는 방법을 잘 모르겠습니다. 이상하게도 C++을 사용했고 헤더 파일에이 문제가 있다는 것을 기억하지 못했습니다.
오류 :
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
코드
#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;
}
코드 (헤더 파일)
#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;
}
작은 따옴표와'# include' 다음에 공백이 없습니까? – mydogisbox
'#include "myDataStructures.h"'사용 (따옴표 사용) – IronMensan
당신은 [include guards] (http://en.wikipedia.org/wiki/Include_guard)를 올바르게 사용하지 않습니다. –