动态变量cpp编译 [英] Dynamic variable cpp compilation

查看:67
本文介绍了动态变量cpp编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望自编译
以来,我可以在.h文件中编辑变量。

I wish I could edit a variable in a .h file since compilation Example:

#include <iostream>
#include <stdlib.h>

#define HOST (char *)"http://localhost/"
#define PATH "insert"

我要像这样从编译中编辑 HOST

I want to edite HOST from compilation like this:

g++ -o output source.cpp -HOST http://mywebsite/


推荐答案

您可以使用以下方法轻松地做到这一点:

You can easily do that with something like this:

#include <iostream>
#include <stdlib.h>

#ifndef HOST
  #define HOST (char*)"http://localhost/"
#endif

#define PATH "insert"

然后,在命令行上,您指定'-DHOST = (char *)随便什么'(它将被使用),或者不传递任何 -DHOST = 标志和默认标志

Then, on the command-line, you either specify '-DHOST=(char*)"whatever"' (and it will be used), or do not pass in any -DHOST= flag, and the default in the header will be used.

这篇关于动态变量cpp编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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