C++ ifndef在不同文件中的工作方式

C++ ifndef在不同文件中的工作方式,c++,c-preprocessor,conditional-compilation,ifndef,C++,C Preprocessor,Conditional Compilation,Ifndef,因此,我试图将main.cpp中声明的库包含到header.h中 //In my main.cpp #include <cmath> #include <deque> #include <vector> using namespace std; //In my header.h #ifndef HANOI_H #define HANOI_H #include <cmath> #include <deque> using nam

因此,我试图将main.cpp中声明的库包含到header.h中

//In my main.cpp
#include <cmath>
#include <deque>
#include <vector>

using namespace std;


//In my header.h
#ifndef HANOI_H
#define HANOI_H

#include <cmath>
#include <deque>

using namespace std;



#endif
//在my main.cpp中
#包括
#包括
#包括
使用名称空间std;
//在我的标题中
#河内ifndef
#定义河内
#包括
#包括
使用名称空间std;
#恩迪夫
这会检查my main.cpp以查看3个库和名称空间是否与相应的变量HANOI_H一起存在吗?

是的,因为执行了
\include
s,它实际上将所有内容替换为1个文件。因此,
#ifndef
从不关心或知道多个文件