C++ 从变量导入文件名

C++ Importing filename from variable

本文关键字:文件名 导入 变量 C++      更新时间:2023-10-16

我有变量"文件名",内容为"code.h",我需要这样做,

#include <filename>

为什么它不起作用?或者 #include 不适用于变量?

#include用于其他头文件而不是变量。如果要有条件地包含头文件,可以使用预编译器命令:

//config.h
#define USE_HEADER_CODE_H
//other.h
#include <config.h>
#if defined(USE_HEADER_CODE_H)
#include <code.h>
#else
#include <other_code.h>
#endif