I have a hometask in witch I can't use any of include directives before the function I should write. But I can use 2 directives given as string arguments of the function . How can I #include
that directives inside of that function?
There is my code and I have no idea how to make it work. (In the final version the main()
part would be deleted, because the code is checked by University's program, and it has it's own main()
)
//START
void SortCount ( string first, string header1, string header2){
#include <header1>
#include <header2>
}
int main(){
string hey = " ";
SortCount (hey, "iostream", "fstream");
return 0;
}
C++ is a static language, hence you are not allowed to add headers dynamically.
You can use gcc to include a file to your build without using #include "file.h"
g++ -include file.h main.cpp main.o
See GCC -include
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.