header file

Hi, How can I create header files and cpp files. I'm using Dev.cpp
Last edited on
I'm guessing file->new->file or something like that.. Why would you have a problem with that?
Why would you have a problem with that?

I will guess that he would be asking about the structure maybe?
file.h
1
2
3
4
5
6
7
8
//include guard, this means that if this file is included more than once
//you wont get multiple definition errors (with classes)
#ifndef FILE_H
#define FILE_H

void func();

#endif 


file.cpp
1
2
3
4
5
#include <iostream>
using namespace std;

void func(){
    cout << it worked!";} 


main.cpp
1
2
3
4
5
6
7
#include <iostream>
#include "file.h"
using namespace std;

int main(){
    func();
    return 0;}


That is the basic implementation of headers and sources. This article has more info: http://cplusplus.com/forum/articles/10627/
Last edited on
I created a class, but I have an error: No such file or directory.
The file being included must be in the same directory (folder) as the file including it. It can also be in a different spot, but unless its in a folder inside the folder with the file including it, using a relative path would be a pain. For files not in your compiler's standard include directory (i.e. YOUR files), you must use quotes for the #include "FILENAME" rather than #include <FILENAME>
Last edited on
I knew, It couldn't help me. You know what ? I used this path: New project > DLL . Was it true ?
Uhm? That would be your IDE. Are you sure that your headers and sources are in the same folder? Are you using quotes (#include "FILENAME") instead of brackets (#include <FILENAME>)? Are you typing the filename correctly? What errors are you getting?
Yes, I 'm sure.
Error: GradeBook.h: No such file or directory.
Well, if you are using quotes to include the file (rather than <> brackets), all your files are in the same directory and your spelling all the filenames correctly, then I don't know what is wrong.
Anyway, thanks
Topic archived. No new replies allowed.