Some mistake with creating .h Files

Hey Guys!

I just wanted to tryout using header files recently and just can't figure out my error. I googled for mostly an hour and it seems so simple for everyone - but still I miss the point to do it right anyhow.

Let me describe it here:

Screen_output.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include <iostream>
#include <fstream>
#include <string>

#ifndef Screen_output.h   
#define Screen_output.h  

class Screen_output
{
	public:
	void title();
} draw;

void Screen_output::title()
{
	string text_line;
	
	ifstream file ("title.txt");
		if (file.is_open()) 
		{
			while(getline(file, text_line))
			{
			cout << text_line << endl;	
			}
			file.close();
		}
}


#endif  


main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// KI Projekt 2.0 (c) Patrick Höfer


#include <fstream>
#include <iostream>
#include <string>
#include <Screen_output.h>

using namespace std;

	
int main() 
{
	draw.title();
	
	



    system("PAUSE");
    return EXIT_SUCCESS;
}



Error Message:

http://my.jetscreenshot.com/13371/20140312-l1mi-31kb

Also here's a screenshot of my project folder:

http://my.jetscreenshot.com/13371/20140312-7qnr-23kb
Change
#include <Screen_output.h>
to
#include "Screen_output.h" .

If you use angle brackets, the compiler preprocessor will only search through the standard include directories.
By putting it in quotes, the preprocessor will first look in the current directory (where the file is) for the header file.
new Error MEssage:

http://my.jetscreenshot.com/13371/20140312-sdgu-58kb

I used this class in main without a header and it worked fine - now there are errors - don't know why exactly - mybe I missed something big with headers?
From:
1
2
#ifndef Screen_output.h   
#define Screen_output.h 

To:
1
2
#ifndef Screen_output_h   
#define Screen_output_h 


I don't think you can use periods in macro names, but I, along with many others, prefer to use all uppercase macro names.
New Error (Sorry for Spamming that stuff):

http://my.jetscreenshot.com/13371/20140312-mi96-55kb

Now it says all my header stuff is undeclared. As I said it worked how it looks earlier in my main.cpp.

Is there a tutorial to get into creating header files with classes ? Because I think I need to start from scratch here since I do so many mistakes.
using namespace std; needs to be added to both files. Yet another reason that statement is the root of all evil for new programmers.
dang....what a trivial error.

I should only use scope operators :: for instead of the using stuff ^^ lesser problems
Topic archived. No new replies allowed.