为什么 iostream 在 Visual Studio 社区中对我不起作用?

Why doesn't iostream work for me in visual studio community?

本文关键字:不起作用 社区 iostream Visual Studio 为什么      更新时间:2023-10-16

我正在写我的第一个程序,它不工作。我正在使用微软visual studio社区,我做了一个控制台应用程序项目。我正在阅读《编程原理与c++实践》,上面写的都是我写的。为什么不工作?

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }

int main()
{
    cout << "Hell, World!n";
    keep_window_open();
    return 0;
}

从你的评论澄清:

unexpected end of file while looking for precompiled header.
Did you forget to add #include "stdafx.h" to your source? 

您的项目属性声明预编译头(可能这是新创建的项目的默认值,记不清了)。

所以只要遵循错误信息中的建议并包含

#include "stdafx.h"

在你的.cpp文件的第一行应该修复这个错误。