假设我有一个简单的代码
// main.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string text = "Hello world.";
cout<<text<<endl;
return 0;
}
运行正常。现在,我要确保它是跨平台的。在github CI上,我在使用许多编译器进行测试时遇到了问题,但在cl.exe
方面遇到困难
cl.exe /std:c++latest main.cpp
严重错误C1083:无法打开包含文件:'iostream':没有此类文件或目录
我知道这是因为Microsoft希望我在我不想做的代码的开头包含stdafx.h
。我尝试了其他一些无效的工作:
cl.exe /std:c++latest /Y- main.cpp
严重错误C1083:无法打开包含文件:'iostream':没有此类文件或目录
cl.exe /std:c++latest /Yc"stdafx.pch" /Yu"stdafx.h" /FI"stdafx.h" main.cpp
严重错误C1083:无法打开预编译的头文件:'stdafx.pch':没有此类文件或目录
cl.exe /std:c++latest /Yu"stdafx.h" /FI"stdafx.h" main.cpp
严重错误C1083:无法打开预编译的头文件:'stdafx.pch':没有此类文件或目录
cl.exe /std:c++latest /Yc"stdafx.h" /FI"stdafx.h" main.cpp
严重错误C1083:无法打开包含文件:'stdafx.h':没有此类文件或目录
那么,解决方案是什么?