关于C++老是出错的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/31 17:40:13
运行C语言没问题,一切都正常!
可是运行C++的时候,老是显示出错!!!例如这个简单的程序:
#include<iostream.h>
void main()
{cout<<"hello";
}
编译时候显示错误:123.obj - 1 error(s), 0 warning(s)
C:\Documents and Settings\Administrator\123.c(3) : error C2065: 'cout' : undeclared identifier
C:\Documents and Settings\Administrator\123.c(3) : error C2297: '<<' : illegal, right operand has type 'char [6]'
执行 cl.exe 时出错.
看了百度提问我运行了这个代码:
#include<iostream>
using namespace std;
void main()
{cout <<"hello"
}
显示错误:e:\vc\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
执行 cl.exe 时出错.
我重新下载又重新安装,都是这个样子,到底什么原因又该怎么处理!!!

把123.c改成123.cpp,另外你下面那个程序的
#include<iostream>
using namespace std;
void main()
{cout <<"hello"; //漏写分号了
}

如果后缀名是C的话,那就得用C语言的格式
#include<stdio.h>
void main()
{printf("hello");
}

还有就是C不能容纳C++,如果后缀名是CPP的话两个都能运行,但是是C的话就只能运行C的文件
在eh.h中有这样的语句
#ifndef __cplusplus
#error "eh.h is only for C++!"
#endif

我查看了以前的问题,你源代码的扩展名是不是c
如果是,要改成cpp

应该是你安装的时候出错了,你的VC++安装的时候自带的函数库里少了个文件,建议你重装下!找个比较安全可靠的安装包!

你的安装包有错误吧。我的运行没错误啊。

改后缀

eh.h你引用了?