Header File

I am using Dev C++ and am having difficulty getting it to recognise my header file. Can someone tell me how to create a header file and include it in my .cpp file? I created a new header file, have code in it and then put #include ".." but it does not find it so it seems

1
2
3
4
5
6
7
  #include "std_lib_facilities.h"

int main()
{
 cout << "Hello\n";
 return 0;   
}


it says things like no such file or directory
Well, you have a few different choices. The simplest - for the time being - is to simply place the header file in the same location (folder or directory) as your .cpp file. If that fails then the name is most likely misspelled.

In the longer term, you might want to put the header in some other location, and configure DevC++ to look in that directory.
You have to create a project which is a collection of header files (.h or .hpp extension), source files (.cpp extension) and the main() program (also .cpp extension). Read up the DevCPP material on how to make a project and save files in it.
As a side note, ditch DevCPP asap and switch to something like Code::Blocks which is updated more regularly (the latest version has C++14 support)
Code::Blocks which is updated more regularly (the latest version has C++14 support)
Does this include the Windows versions? Last time I tried code::blocks it came with a compiler which supported C++11 but I don't know, has it since been updated?

It appears to come with TDM-GCC version 4.9.2, which is getting a bit antiquated, relatively speaking. (That's actually the same version number as the compiler which comes with Orwell DevC++).
Last edited on
closed account (E0p9LyTq)
With Code:Blocks you don't have to use the compiler that comes with the download package. You can use any compiler with C:B so getting a more up-to-date compiler is not a problem.

If you can afford the download you might want to get Microsoft's Visual Studio Community 2015. It is free, but is not as small as Code:Blocks or DevC++.

I recommend downloading the ISO. To get Visual C++ installed you need to do a custom install.
Does this include the Windows versions? Last time I tried code::blocks it came with a compiler which supported C+ +11 but I don't know, has it since been updated?


Yes, I'm running it on W10, upgraded around a month back. If you go to Compiler-Settings-Compiler Flags you'll see only the flag for C++11 is available but check Other Complier Options next to it: it should have -std=c++14 and does, for eg, make_unique() which was not available for C++11
Topic archived. No new replies allowed.