为什么我用vs2010编c++程序时,用“cout”“cin”时,调试时说“cout”“cin”是未声明的标识符?

#include<iostream>
#include<math.h>

double max(double x, double y);

void main()
{
double a,b,c;
cout<<"input two number:\n";
cin>>a>>b;
c=max(a,b);
cout<<"the squart of maximum="<<sqrt(c);
}
double max(double x, double y)
{
if(x>y)
return x;
else
return y;
}
1>d:\可删\c文\help 2\help 2\较大数平方根.cpp(9): error C2065: “cout”: 未声明的标识符
1>d:\可删\c文\help 2\help 2\较大数平方根.cpp(10): error C2065: “cin”: 未声明的标识符
1>d:\可删\c文\help 2\help 2\较大数平方根.cpp(12): error C2065: “cout”: 未声明的标识符
1>

在cout和cin的前面加上std:: 即std::cout和std::cin
表明cout和cin是定义在std命名空间内的对象
或者在#include <math.h>下面加上using namespace std;追问

为什么有些软件不用加using namespace std?这是我的安装的软件问题还是什么??我用的是VS2010中文版

追答

不用加命名空间声明?对VS2010我不太了解,但是我觉得你没加using namespace std;
可能是你没有用到命名空间std中声明或定义的类型,像下面的程序一样:
# include
int main(void)
{
int a, b;
printf("10\n");
return 0;
}
类似这样的程序不用加命名空间声明,因为你根本没用到像cin,cout 还有一些在std命名空间中声明或定义的类型,自然就不需要了。
还有问题请加我扣扣:(九0648864六)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-08
要加上using namespace std;
第2个回答  2011-09-08
#include <tchar.h>
第3个回答  2011-09-08
没有利用命令空间吧 using namespace std;
第4个回答  2011-09-08
用VS2010运行了此程序!可以正常运行,没发现问题!