📄 l10_10.cpp
字号:
#include<iostream.h>
# include <fstream.h>
#include<string.h>
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;
}
void main()
{
CRect rt;
ifstream ifs( "data.txt" );
ifs.seekg( 0, ios::end );
streampos lof = ifs.tellg();
ifs.seekg( -lof/10, ios::end );
ifs.read( (char *)&rt , sizeof(CRect) );
ifs.close();
rt.Move(100,100);
ofstream ofs( "data.txt", ios::ate );
ofs.seekp( -lof/10, ios::end );
ofs.write( (char *)&rt , sizeof(CRect) );
ofs.close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -