CIN,COUT 未删除标识符
CIN, COUT Undelcared Identifier
所以我仔细阅读了其他一些文章,但我似乎找不到为什么这不起作用的原因。我是新来的C++所以请善待。
// User Pay.cpp : Defines the entry point for the console application.
// This program calculates the user's pay.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double hours, rate, pay;
// Get the number of hours worked.
cout << "how many hours did you work? ";
cin >> hours;
// Get the hourly pay rate.
cout << "How much do you get paid per hour? ";
cin >> rate;
//C alculates the Pay.
pay = hours * rate;
// Display the pay.
cout << "You have earned $" << pay << endl;
return 0;
}
你不需要包含 #include"stdafx.h"。
此外,将来更好的做法是不要包含整个 std 库("使用命名空间 std")。取而代之的是,您可以直接调用 std::cout、std::cin 等...
此外,在代码末尾的"return 0"之前进行系统("暂停")调用也会有所帮助(在您的示例中)。因此,当程序执行时,控制台不会关闭,您可以看到结果。
代码示例:
#include <iostream>
//using namespace std;
int main()
{
double hours, rate, pay;
// Get the number of hours worked.
std::cout << "how many hours did you work? ";
std::cin >> hours;
// Get the hourly pay rate.
std::cout << "How much do you get paid per hour? ";
std::cin >> rate;
//C alculates the Pay.
pay = hours * rate;
// Display the pay.
std::cout << "You have earned $" << pay << std::endl;
system("PAUSE");
return 0;
}
尝试创建一个空项目(取消选中预编译标头)。 然后复制您的代码,但删除 #include"stdafx.h"。
看起来好像你有一个错误,然后添加:
`using namespace std;`
现在应该没有错误。
相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- #ifdef和未声明的标识符
- 将指针设置为"nullptr"并不能防止双重删除?
- 删除动态数组时未定义标识符
- 如何在C++中为增加但记住删除先前对象的对象分配唯一标识符
- 在开关盒循环中使用未删除的标识符来解析 CSV 文件
- CIN,COUT 未删除标识符