lixiuchun717 发表于 2008-6-13 12:39

请教一个问题,能快点给我帮助吗

#include <iostream.h>
int main()
{
int a;
cout<<"请输入一个数字,按回车结束"<<endl;
cin>> a;
cout<<a<<endl;
return 0;
}

在编译时会出现如下提示:

:\lxc\study\l.c(5) : error C2065: 'cout' : undeclared identifier
d:\lxc\study\l.c(5) : error C2297: '<<' : illegal, right operand has type 'char [27]'
d:\lxc\study\l.c(5) : error C2065: 'endl' : undeclared identifier
d:\lxc\study\l.c(6) : error C2065: 'cin' : undeclared identifier
d:\lxc\study\l.c(6) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
d:\lxc\study\l.c(7) : warning C4552: '<<' : operator has no effect; expected operator with side-effect

若是人间 发表于 2008-6-13 18:14

缺少using namespace std;

若是人间 发表于 2008-6-13 18:18

这个程序没问题,能用呀

afraid 发表于 2008-6-13 19:09

和编译器有关?。。。

jayklx 发表于 2008-6-20 15:03

一楼正解。cout cin 等都是属于命名空间 std。。。

辛令超 发表于 2008-6-20 15:53

和编译器有关

koolism 发表于 2008-6-20 20:38

<iostream.h>不需要指定命名空间
而<iostream>要指定命名空间

楼主的问题应该是编译器的问题

守鹤 发表于 2008-6-20 23:55

1."iostream.h"是基于C语言的头文件,而
   “iostream”是C++的标准格式。
2.两者都可在vc++中使用,但后者必须使用命名空间
   即  using namespace std;已解决重名冲突的问题。
3.你的程序没有错误,可能是编译器的问题
  或着你可以再建一个工程,创建C++文件,在进行编译一次。

页: [1]

编程论坛