VC++问题输入输出

来源:百度知道 编辑:UC知道 时间:2024/09/19 15:49:56
#include<iostream.h>
void main()
{
int m;
char ch;
cout<<"请输入整数m的值:"<<endl;
cin>>m;
cout<<"请输入字符ch:"<<endl;
cin>>ch;
cout<<"m="<<m<<endl<<"ch="<<ch<<endl;
}

我照着树上的输入,为什么出现这么多错误?
ABC.C(6) : error C2065: 'cout' : undeclared identifier
ABC.C(6) : error C2297: '<<' : illegal, right operand has type 'char [17]'
ABC.C(6) : error C2065: 'endl' : undeclared identifier
ABC.C(7) : error C2065: 'cin' : undeclared identifier
ABC.C(7) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
ABC.C(8) : error C2297: '<<' : illegal, right operand has type 'char [14]'
ABC.C(9) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
AB

试试

#include <iostream>
using namespace std;

void main()
{
int m;
char ch;
cout<<"请输入整数m的值:"<<endl;
cin>>m;
cout<<"请输入字符ch:"<<endl;
cin>>ch;
cout<<"m="<<m<<endl<<"ch="<<ch<<endl;
}

#include<iostream.h>
这一行改成
#include<iostream>
就行啦!

代码没有问题。
你看看是不是工程选错了?
建一个控制台应用程序

我建了个控制台应用程序,把上面的代码拷贝过去,没有问题。

将#include<iostream.h> 改成 #include"iostream.h"试下出错原因是因为头文件没有被正常包含进去。