0

I recently adopted a style where I try to avoid unnecesary classes / scopes, so the code cannot be splitted in files by classes or functions, since almost everything happens in main. Of course for a lot of lines of code, this will be pretty hard to read, so I must split it somehow. I would like to do something like this:

#include <iostream>
int main()
{
    #include "test.cpp"
    return 0;
}

// test.cpp
std::cout << "Test";

Is there a way to tell the compiler to copy it exactly like that? And if yes, can I also make use of the IntelliSense (VS 2017)?

Popescu Flaviu
  • 95
  • 2
  • 11

1 Answers1

1

Regardless of the design is a good or a bad idea, you can check what the "final" output file looks like. If you are using GCC, you can use -E flag, e.g.

g++ -E main.cpp > out

This command executes the preprocessor and write the output to the out file. In this example, my out file looks like

// bunch of STL codes due to <iostream>
// ...

# 2 "main.cpp"
int main()
{
# 1 "test.cpp" 1
std::cout << "Test";
# 5 "main.cpp" 2
  return 0;
}

Firman
  • 928
  • 7
  • 15