【问题标题】:Why doesn't iostream work for me in visual studio community? [closed]为什么 iostream 在 Visual Studio 社区中不适合我? [关闭]
【发布时间】:2015-10-19 17:01:26
【问题描述】:

我正在编写我的第一个程序,但它不工作。我正在使用 Microsoft 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;
}

【问题讨论】:

  • 什么不起作用?它编译吗?关联?跑?如果它运行,行为是什么?
  • 你希望它如何运行?
  • 它在寻找预编译头文件时说文件意外结束。您是否忘记将#include "stdafx.h" 添加到您的源代码中?
  • 关闭预编译头选项再试一次。
  • 你为什么没有阅读错误信息???

标签: c++ visual-studio visual-studio-2010 visual-studio-2012


【解决方案1】:

来自你们的 cmets 澄清:

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

Precompiled Headers 的项目属性声明(可能是新创建项目的默认值,记不清了)。

所以只需遵循错误消息中的建议并包括

#include "stdafx.h"

.cpp 文件的第一行应该可以修复错误。

【讨论】:

  • 为什么不直接禁用预编译头选项?
  • @zenith:为什么不添加包含?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
  • 2016-08-03
  • 2014-12-05
相关资源
最近更新 更多