c++ - Visual C++ 不允许 iostream

标签 c++ iostream

我刚开始使用 C++ 我正在阅读电子书从 C++ 开始第 7 版。我从书中复制了代码并将其放入带有预编译头文件的新项目 w32 控制台应用程序下的 Visual 中。好吧,当我在预处理器指令行中使用 iostream 时,我得到...我四处搜索但不明白为什么 iostream 不起作用,有什么帮助吗?

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 }

最佳答案

不是因为iostream,而是因为你忘了包含stdafx.h

错误很明显。如果您使用预编译 header 构建项目,则必须在实现文件的开头包含 stdafx.h

关于c++ - Visual C++ 不允许 iostream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9291485/

相关文章:

c++ - 无法生成随机数?

c++ - MPI 和全局对象 : All ranks have the object at same memory address?

c++ - 使用 iostream << 序列化用户对象

c++ - 带有颜色和标题的 std::clog 包装器无法正确打印整数

c++ - 使用 std::cout 添加时间戳

c++ - 编写版本特定的 C++ 代码以检测 std 命名空间中的符号

c++ - "is defined"宏检查及其调用必须处于不同的条件下吗?

c++ - tr1::randgen() 上的竞争条件,即使使用 #pragma omp critical

c++ - C++读取二进制文件

c++ - std::setw() 和 ostream::width() 之间的类型不一致