error : unterminated #ifndef

Aug 19, 2019 at 11:44am
Hey, umm I'm a beginner at c++ and have no idea why this error is happening :(

error : unterminated #ifndef



Burrito2.h
1
2
3
4
5
6
7
8
9
10
11
12
1 #ifndef BURRITO2_H
2 #define BURRITO2_H
3 
4 
5 class Burrito2
6 {
7     public:
8         Burrito2();
9         
10 };
11 
12 #endif // BURRITO2_H 




main.cpp
1
2
3
4
5
6
7
8
9
1 #include <iostream>
2 #include "Burrito2.h"
3 using namespace std;
4
5 int main()
6 {
7     Burrito2 bo;
8     return 0;
9 }




Burrito2.cpp
1
2
3
4
5
6
7
8
9
1 #include "Burrito2.h"
2 #include <iostream>
3
4 using namespace std;
5
6 Burrito2::Burrito2()
7 {
8     cout << "i am a banana" << endl;
9 }
Last edited on Aug 19, 2019 at 11:46am
Aug 19, 2019 at 11:58am
Does the compiler state the file, where error occurs?
Aug 19, 2019 at 4:00pm
Hello sohui,

In addition to keskiverto's question are the line numbers in the files?

When I loaded up your files in my IDE, (VS2017), minus the line numbers I could not duplicate your error.

Not sure what you did using the code tags, but they do not put the line numbers in side the block unless you copy a pasted it that way.

In "Burrito2.cpp" you have:
1
2
#include "Burrito2.hpp"
#include <iostream> 

Sometimes this will make no difference, but at other times it does. I tend to like this order better.
1
2
3
#include <iostream>

#include "Burrito2.hpp" 

I like the ".hpp"extension better than the ".h" extension when using a C++ program. The ".h" makes me think it is a C header file when it is not.

With "Burrito2.hpp" being last the header file(s) that come before are compiled first and anything in the "Burrito2.hpp" file that would need the above header files is covered. I use the blank line to break the standard include files the ones in the (<>)s from the files that I would write, the ones in ("")s.

Hope that helps,

Andy
Aug 20, 2019 at 4:19am
I was able to run code without errors and didn't edit the files. Maybe try BURRITO2_H_.
Topic archived. No new replies allowed.