注册 登录
编程论坛 C++教室

c语言编程

心灵百合 发布于 2011-10-29 17:57, 1079 次点击
为什么Microsoft Visual C++ 6.0能编译C语言代码,而不能编译C++代码。
如:
#include"iostream.h"

int add(int x,int y)
{
    int z;
    z=x+y;
    return z;
}
void main()
{
    int a,b,c;

    cin>>a>>b;
    c=add(a,b);
    cout<<c<<endl;
}
而编译时报错!
--------------------Configuration: cp_1 - Win32 Debug--------------------
Compiling...
test.c
F:\VC 6\MyProjects\cp_1\test.c(13) : error C2065: 'cin' : undeclared identifier
F:\VC 6\MyProjects\cp_1\test.c(13) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
F:\VC 6\MyProjects\cp_1\test.c(15) : error C2065: 'cout' : undeclared identifier
F:\VC 6\MyProjects\cp_1\test.c(15) : error C2065: 'endl' : undeclared identifier
F:\VC 6\MyProjects\cp_1\test.c(15) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
Error executing cl.exe.

test.obj - 3 error(s), 2 warning(s)
求大侠指点,谢谢!
1 回复
#2
nomify2011-10-30 02:17
程序代码:
#include <iostream>
using namespace std;

int add(int x,int y)
{
    int z;
    z=x+y;
    return z;
}
void main()
{
    int a,b,c;

    cin>>a>>b;
    c=add(a,b);
    cout<<c<<endl;
}
1