Visual C ++不允许iostream [英] Visual C++ not allowing iostream
问题描述
我刚刚开始C ++我正在读电子书开始与C ++第7版。我从书中复制代码,并将其放入Visual,在新项目w32控制台应用程序与预编译头。当我在预处理器指令行中使用iostream时,我得到..我搜索,不明白为什么iostream将不工作,任何帮助?
I just started C++ I am reading the ebook Starting out with C++ 7th edition. I copied the code from the book and put it into Visual, under new project w32 console app with precompiled headers. Well When I use the iostream in the preprocessor directive line i get.. I searched around and do not understand why the iostream won't work, any help?
1>------ Build started: Project: dd, Configuration: Debug Win32 ------
1> stdafx.cpp 1> dd.cpp 1>c:\documents and settings\leon\my documents\visual studio 2010\projects\dd\dd\dd.cpp(24): fatal error
C1010: unexpected end of file while looking for precompiled header.
Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
1 // This program calculates the user's pay.
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 double hours, rate, pay;
8
9 // Get the number of hours worked.
10 cout << "How many hours did you work? ";
11 cin >> hours;
12
13 // Get the hourly pay rate.
14 cout << "How much do you get paid per hour? ";
15 cin >> rate;
16
17 // Calculate the pay.
18 pay = hours * rate;
19
20 // Display the pay.
21 cout << "You have earned $" << pay << endl;
22 return 0;
23 }
推荐答案
可以使用所谓的预编译头文件。这是一个帮助加快项目建设的技术。为了这个工作,你需要 #include
文件stdafx.h作为你在源文件中做的第一件事。
In Visual C++, project can use what is called "pre-compiled headers". This is a technique to help speed up building of the project. For this to work you need to #include
the file "stdafx.h" as the first thing you do in the source file.
因此在添加iostream之前添加此行:
So add this line before the inclusion of iostream:
#include "stdafx.h"
再次构建时应该可以正常工作。
When you build again it should work.
这篇关于Visual C ++不允许iostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!