关于类的C++ ,有一个错误

来源:百度知道 编辑:UC知道 时间:2024/06/20 02:10:36
#include <iosrtream.h>

class tree{
int height;
public:
tree(int initialHeight); //constructor构造函数
~tree(); //Disconstructor
void printsize();
};
tree::tree(int initialHeight) {
height=initinitialHeight;
}
tree::~tree(){
cout<<"inside tree destrustor";
printsize();
}
void tree::grow(int years){
height+=years;
}
void tree::printsize(){
cout<<"tree height is"<<height;
}
void main()
{cout<<"before opening brace";
{
tree t(12);
cout<<"after tree creation";
t.printsize();
t.grow(4);
cout<<"before closing brace";
}
cout<<"after closing brace";
}

Compiling...
类.cpp
h:\c++上机\4.8+\类.cpp(1) : fatal error C1083: Cannot open include file: 'iosrtream.h': No such file or di

#include <iostream>//这里
using namespace std;
class tree{
int height;
public:
void grow(int);
tree(int initialHeight); //constructor构造函数
~tree(); //Disconstructor
void printsize();
};
tree::tree(int initialHeight) {
height=initialHeight;//这里
}
tree::~tree(){
cout<<"inside tree destrustor";
printsize();
}
void tree::grow(int years){//这里tree 里根本没有grow这个函数
height+=years;
}
void tree::printsize(){
cout<<"tree height is"<<height;
}
int main()
{cout<<"before opening brace";
{
tree t(12);
cout<<"after tree creation";
t.printsize();
t.grow(4);
cout<<"before closing brace";
}
cout<<"after closing brace";
system("pause");
return 0;
}

对照着看看吧

全盘搜索
文件
iosrtream.h

然后拷贝