this question looks familiar but trust me it actually is not ! Let me explain why. This is not about saving a function in a header file and including and calling it. An example will illustrate my query clearly so here we go: I have a program like the following:
#include whatever_should_be_included
int main()
{
whatever-1
whatever-2
whatever-3
.
.
.
}
All those whatevers are codes in the program, including if
conditions, loop
s and really whatever. I want those "whatever"s to be saved in files, let's say plain text files or whatever extension is necessary, let's say "exten
" be the extensions, then I want to save them as:
chunk-1.exten
, chunk-2.exten
, .... etc files that will contain: whatever-1
, whatever-2
,... etc chunks of lines of codes and my program now should look like:
#include whatever_should_be_included
#include those_chunks_maybe
int main(){
chunk-1.exten; //or whatever syntax necessary
chunk2.exten;
chunk-3.exten;
.
.
.
}
I am a beginner in C++ and in programming in general so please go easy on me :) a step by step clear answer with a bit of explanation will be really appreciated.
Edit-1:
I am using Ubuntu 16.04
My compiler is g++ although I am not directly using it, I am compiling or rather loading the programs inside the CERN's ROOT shell, as root macros.
Edit-2:
Of course a better way to go is to use functions and headers, but that does not mean that we cannot explore this feature of chunking out plain code-texts to different files and include them inside the main ! I wanted to learn this and I don't understand how learning this (however dull) feature is wrong !! Why voting negative exactly ? Is this question harming people ? Is it not curious and promote knowledge ?