Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize a C++ project [closed]

Tags:

I would like to know what are C++ best practices when it comes to organizing my project. I've read that I should put all the source files (.cpp) in the src folder and header files (.h) should be placed in the include folder. Is it the way it is supposed to be, or should I put my header files in the source files folder?

This is my folder tree structure

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
like image 234
paxilpaz Avatar asked May 28 '12 09:05

paxilpaz


People also ask

What are the two main ways a file can be organized in C?

Writing to a file (fprintf or fputs)

Why we use header files in C?

The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program. In C, the usual convention is to give header files names that end with .


1 Answers

It is a matter of preference really but organization of a code base helps for maintainability as well as for easily understanding the code. One should have an Modular approach as much as possible. Your code organization just looks about almost right, Ideally I would have:

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
|
+--- bin (generated binaries)
|
+--- lib (external dependencies)
like image 123
Alok Save Avatar answered Oct 25 '22 09:10

Alok Save