c++ Very beginner question on multiple files

It's technically not necessary, but highly recommended. These are the two big reasons I can think of to split your code into multiple files (header files included)

  1. It's good organization! Shoving every class and function further and further down in an endless single file is confusing when you come back to it later. If you have multiple files with meaningful names, it's easier too see what-does-what and it gives a basic structure to your program.

  2. Better compiled times Every time you compiled that single file, it has to compile everything. Even if you just add a single semicolon, it will have to compile everything you wrote a week ago. This isn't a problem with smaller programs, but as your program grows it's better to split up your work into multiple files, as it will be quicker to compile only the small snippet of code that you just wrote in a single file than all your code.

/r/learnprogramming Thread