Header files in dev-C++

后端 未结 5 1813
难免孤独
难免孤独 2021-01-21 00:07

I\'m trying to add an header file to dev-C++ but when I compile it it doesn\'t work. Here are my exact steps (for my example, I\'m trying to get mysql.h to work):

相关标签:
5条回答
  • 2021-01-21 00:19

    You didn't say how you included it at the top of your file. This should work if you did

    #include "mysql.h"
    

    rather than

    #include <mysql>
    

    which is a mistake that people sometimes make.

    EDIT: Perhaps try using relative paths rather than an absolute path (as you seem to be doing) when specifying additional include directories? I don't know if that would make a difference (and I don't have the time to check) but I've always used relative paths and it's always worked for me (it's also good practice anyway). So, instead of

    C:\Projects\ProjectName\Include

    something like

    \Include or ..\Include depending on your project file structure.

    0 讨论(0)
  • 2021-01-21 00:21

    Its very simple ...

    Just make Your header file and save it as .h extension.

    Then use #include "file_name.h" instead of using include

    Example- This is my header file.

    #include<iostream>
         using namespace std;
    
         namespace Ritesh
             {
                 int a;
                 int b;
                 void sum();
             }
         void Ritesh::sum()
             {
                 cout<<a+b;
             }
    

    Then use of it-

    #include<iostream>
    #include "Ritesh.h"
       using namespace std;
       using namespace Ritesh;
       int main()
           {
               a=4;b=6;
               sum();
           }
    

    Output- Output of program

    0 讨论(0)
  • 2021-01-21 00:34

    I had the same problem....

    You need to put the #include after "using namespace std;", in order to use your header file in the standard namespace.

    For me it is working.

    Best wishes.

    0 讨论(0)
  • 2021-01-21 00:40

    Dev-C++ is a port of GCC, so try this page: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html.

    Note that you probably have to tinkle with the Makefile.

    0 讨论(0)
  • 2021-01-21 00:41

    On the left side, right click the Project and choose "Add to Project", and then select the header file.

    0 讨论(0)
提交回复
热议问题