Suppose my program (X) is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream> //etc
int main()
{
definitions of a lot of variables here //call this chunk variable-chunk
if(condition 1){ do a lot of things 1}; //call this chunk condition chunk
for(int i blah blah blah){ do the looping and also a lot of stuff inside... } //call this the loop chunk
here goes a few paragraphs of other codes... //call this misc-chunk
}
|
I need those chunks to be cut and pasted into files named
variable-chunk.extension, condition-chunk.extension, ...
etc. and I want those files to be put at those exact positions by using
include
or something like that, so that they act like as if they paste their contents at those positions in the
main
program. So the final code should look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream> //etc
#include <those created chunk files maybe ?>
int main()
{
variable-chunk.extension must be called here
condition-chunk.extension should be called here
etc
}
|
But I do not want those chunk files to be function like because then I have to pass the variables (defined inside
variable-chunk.extension
file) as
arguments
to all those files, I don't want that. I just want those chunk files to act as fragments of my program, plain dull code-texts pasted from those chunk-files and read by the main program.. no issues with variables etc, the variables defined inside the
variable-chunk.extension
should do the job once and for all.
Can this be done ?
PS: Regarding your comment:
"
#include
is equivalent to copy paste the content of the file.", doesn't seem like so. If I cut and paste the fragments of my program in some files and simply include them wherever necessary, the compiler says that the variables used inside those files are not defined in the current scope, but I surely defined the variables in the beginning of my main program.