#include预处理器 [英] #include preprocessor

查看:86
本文介绍了#include预处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用预处理器在#include中添加双引号吗?

我想创建一个预处理器宏,说FULL_PATH,我将使用它来#include文件,如下所示

Does anyone know how to pre-pend and append a double quote in a #include using the preprocessor?

I would like to create a preprocessor macro say FULL_PATH that I will use to #include files as followed

#include FULL_PATH(PATH, FILE_NAME)


我确实希望减少使用VC ++包含环境变量,因为它们很讨厌与我和其他人编写的许多项目一起使用,尤其是在某些项目偶尔具有相同名称的文件时.

我在下面尝试了一个例子


I do want to use VC++ Include Environment Variables less since they are annoying to utilize with dozens of projects written by me and other people, especially when some projects occasionally have files with the same name.

I''ve tried an example below

#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
#define BOOST_DO_JOIN2( X, Y ) X##Y
#define  boost_dir( __X ) BOOST_JOIN("C:/Boost/boost_1_44_0/", #__X)


#pragma message( boost_dir(boost/thread/mutex.hpp) )
#include boost_dir(boost/thread/mutex.hpp)


#pragma消息会扩展为正确的文件名
C:/Boost/boost_1_44_0/boost/thread/mutex.hpp

但是#include无效.可能缺少双引号.
严重错误C1083:无法打开包含文件:``C:/Boost/boost_1_44_0/'':权限被拒绝

如果我添加双引号作为前缀和后缀,则代码是否为


The #pragma message expands to the correct file name
C:/Boost/boost_1_44_0/boost/thread/mutex.hpp

The #include does not work however; possibly missing double quotes.
fatal error C1083: Cannot open include file: ''C:/Boost/boost_1_44_0/'': Permission denied

If I add a double quote as a prefix and suffix, it''s is if the code was

#include "\"C:/Boost/boost_1_44_0/boost/thread/mutex.hpp\""


当我希望它成为


when I would want it to be

#include "C:/Boost/boost_1_44_0/boost/thread/mutex.hpp"

推荐答案

这有效:
#define boost_dir( __X ) "C:/Boost/boost_1_44_0/" __X
	cout << boost_dir("/boost/thread/mutex.hpp") << endl;


因此,适应起来应该非常简单.


so should be fairly simple to adapt.


当我使用预处理器VS2010_dir创建路径时,就会出现不一致的情况,例如:

#define VS2010_dir(C:/Documents and Settings/Ted/My Documents/Visual Studio 2010/Projects/__ X)
#define error_code_dir(__ X)VS2010_dir(Error_Code/Include/__ X)
#include error_code_dir(Error_Code.h)
The inconsistency occurs when I create the path using the preprocessor VS2010_dir, for example:

#define VS2010_dir(C:/Documents and Settings/Ted/My Documents/Visual Studio 2010/Projects/__X)
#define error_code_dir(__X) VS2010_dir(Error_Code/Include/__X)
#include error_code_dir(Error_Code.h)


这篇关于#include预处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆