首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

#ifndef 用法疑点

2013-03-20 
#ifndef 用法疑问文件1#ifndef 1#define 1#includeiostream#include stringusing namespace std#endi

#ifndef 用法疑问
文件1
#ifndef 1
#define 1
#include<iostream>
#include <string>
using namespace std;
#endif
文件2
#ifndef 2
#define 2
#include<iostream>
#include <string>
using namespace std;
#endif
如果文件3同时#include<文件1>#include<文件2>那么#include<iostream>#include <string>不会被重复用吗,不太理解#ifndef 用法,求正解。
[解决办法]
string有它自己的#ifndef guard,第一次被包了以后第二次就不包了。
[解决办法]
#include <iostream>、#include <string>中也会有如下:


#ifndef IOSTREAM_H
#define IOSTREAM_H
//iostream类的定义
#endif

包含了一次就不会有包含第二次了,所以不会重复

热点排行