c++ 基础问题求教!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:54:00
#include<iostream.h>
class see()
{
public:
void out()
{
cout<<"hello world!!"<<endl;
}
};
void main()
{
see se;
se.out();
}
---------------错误如下--------------
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\c\1\1.cpp(4) : error C2143: syntax error : missing ';' before 'public'
D:\c\1\1.cpp(6) : error C2143: syntax error : missing ';' before '{'
D:\c\1\1.cpp(11) : warning C4508: 'see' : function should return a value; 'void' return type assumed
D:\c\1\1.cpp(14) : error C2146: syntax error : missing ';' before identifier 'se'
D:\c\1\1.cpp(14) : warning C4551: function call missing argument list
D:\c\1\1.cpp(14) : error C2065: 'se' : undeclared identifier
D:&

#include<iostream.h>
class see/////////////////这里不能用()
{
public:
void out()
{
cout<<"hello world!!"<<endl;
}
};
void main()
{
see se;
se.out();
}

C++的iostream好像不需要.h哦,see()是函数还是类?删了括号。}不需要;吧?把它删了

问题产生主要原因:
定义的see类后的()是多余的,去掉之后编译就不会有问题,可以顺利通过了。

建议:虽然改掉以上的疏忽之处后,就没有问题了。但是看你的程序还是不够规范——即不够标准。在标准的c++程序中,要有命名空间using namespace std;,main函数的类型应该为int,且最后因加上return 语句,如果加上了命名空间,引用头文件时就可以去掉后缀名.h了(不去好像还不对呢!)修改样式如下,仅供参考:
#include<iostream>
using namespace std;
class see{
public:
void out(){
cout<<"hello world!!"<<endl;
}
};
int main(){
see se;
se.out();
return 0;
}

如何?想来你该明白了!祝你进步!!

把程序改成这样就可以运行了,你用的头文件是C语言的,改成C++的给你
#include<iostream>
using namespace std;
class see
{
public:
void out()
{
c