如何判斷 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