动态变量cpp编译

编程入门 行业动态 更新时间:2024-10-23 15:31:20
本文介绍了动态变量cpp编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

#include <iostream> #include <stdlib.h> #define HOST (char *)"localhost/" #define PATH "insert"

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

I want to edite HOST from compilation like this:

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

推荐答案

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

You can easily do that with something like this:

#include <iostream> #include <stdlib.h> #ifndef HOST #define HOST (char*)"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编译

本文发布于:2023-11-28 07:27:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   动态   cpp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!