C++头文件位置:/usr/include/c++ 这个下面就是C++标准头文件
test.cpp:
#include <iostream> //注意这里 不是iostream.h
#include <string.h>
using namespace std;
class CRect
{
private:
char color[10];
int left;
int top;
int length;
int width;
public:
void SetColor(char *c);
void SetSize(int l, int w);
void Move(int t,int l);
void Draw();
};
void CRect::SetColor(char *c)
{
strcpy(color, c);
}
void CRect::SetSize(int l, int w)
{
length=l;
width = w;
}
void CRect::Move(int t,int l)
{
top = t;
left = l;
}
void CRect::Draw()
{
cout << "矩形左上角坐标为(" << left << "," << top << ")" << endl;
cout << "矩形长和宽分别为" << length << "," << width << endl;
cout << "矩形的颜色是" << color << endl;
}
int main()
{
CRect r;
r.SetColor("Red");
r.Move(10,20);
r.SetSize(100,200);
r.Draw();
r.Move(50,50);
r.SetColor("Blue");
r.Draw();
}
makefile :
all:test
g++ -o test test.cpp
clean:
rm test