[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
C++的编译环境千奇百怪,很多时候一些代码在某些编译环境下可用,一旦移到其他环境下,就会干脆Compile Error
对此,我们可以使用C++的宏定义来判断操作系统,从而进行一些有趣的操作(貌似意义不大)
比如这样
* #include<iostream>
* #if !defined(_WIN32)//如果我使用的不是WIN32操作系统
* #include<bits/stdc++.h>//那我就打开万能头文件
* #endif //if要和endif搭配使用
* using namespace std;
* int main()
* {
* cout << "hello world" << endl;
* return ;
* }
对于上面这段代码,vs不允许使用万能头,所以就让他自己去判断一下编译环境是不是Windows,如果不是Windows,而是OJ什么的,那就打开万能头文件
也就是说
我们可以通过 #if defined(XXXX)或者#ifdef XXXX这样的语句来判断当前的操作系统,根据操作系统的不同进行不同操作
而且有趣的是,只要#if与#endif之间的操作在当前编译器下不被执行,不管写什么乱七八糟的东西都不会Compile Error
借助这个操作,我们甚至可以写两个main()函数
* #include<iostream>
* using namespace std;
* #if defined(_WIN32)
* int main()
* {
* cout << "hello world" << endl;
* return ;
* }
* #else
* int main()
* {
* cout << "HELLO WORLD" << endl;
* return ;
* }
* #endif
这样的源代码在不同的环境下编译就是完全不同的效果
系统宏定义:
* UNIX _unix
or _unix_
* Linux _linux
or _linux_
* Windows32 _WIN32
* Windows64 _WIN64
* IOS __APPLE__
* android __ANDROID__
编译器宏定义
*
GCC __GNUC__
*
Visual C++ _MSC_VER
*
Borland C++ __BORLANDC__