如何使用#DEFINE替换#include中的字符串 [英] How to replace a string in #include define by using #DEFINE

查看:371
本文介绍了如何使用#DEFINE替换#include中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始的#include字符串是这样的:


#include" my_path1 \Includes\types.h"


I想要改变这样的话


#DEFINE MY_PATH my_path1


#include" MY_PATH\include\types.h"


这是无法编译的。是否需要$()或其他符号?

The original #include string like this:

#include "my_path1\Includes\types.h"

I want to change like this

#DEFINE MY_PATH my_path1

#include "MY_PATH\include\types.h"

This can not be compiled. Is there a $() or other symbol needed?

推荐答案

()或需要其他符号?


\是转义序列字符,如\ n。 \之后的字符是代码。要获得实际的反斜杠,必须使用\\。在这种情况下,\后面的字符是\,这是字符\的代码,所以最终结果是一个\。


你的路径应该是:
The \ is an escape sequence character, like \n. The character after the \ is a code. To have an actual backslash, you must use \\. In this case the character after the \ is a \ which is a code for the character \ so the end result is one \.

Your path should be:
展开 | 选择 | Wrap | 行号


糟糕。我忘记了第二个\。让我再试一次:

Oops. I forgot the second \. Let me try again:

展开 | 选择 | Wrap | 行号


这篇关于如何使用#DEFINE替换#include中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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