我正在嘗試編寫一個在Borland C++和Visual C++中編譯的程序。要做到這一點,我添加#ifdef _MSC_VER
包括stdafx.h文件,當源編譯在VS.代碼編譯和Borland的C++執行OK,但在VS,它失敗:爲什麼我有條件地包含stdafx.h後會出現編譯錯誤?
錯誤C1020:意外#ENDIF
#ifdef _MSC_VER //I'm in VS
#include "stdafx.h"
#endif //this line doesn't compile in VS
#ifdef __BORLANDC__ //I'm in Borland
#pragma hdrstop
#pragma argsused
#endif
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello" << std::endl;
std::cin.get();
return 0;
}
如何解決這個問題?