如何判断 C++ 代码是在 32 位还是 64 位系统中编译的?
在 C++ 中,没有直接的方法来检查环境架构。对于 Windows 系统,可以使用两个宏来检查架构。这些宏是 _WIN64 和 _WIN32。当系统为 64 位时,则 _WIN64 将为 1,否则 _WIN32 将为 1。因此我们可以通过宏检查来识别架构。
示例
#include <iostream>
using namespace std;
int main() {
#ifdef _WIN64
cout << "This is 64 bit system" << endl;
#elif _WIN32
cout << "This is 32 bit system" << endl;
#endif
}输出
This is 64 bit system
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP