⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shiyan14.cpp

📁 学习c++的一些实例程序
💻 CPP
字号:
#include<fstream.h>
#include<iostream.h>
class Mailman
{	
public:
	bool bHaveMsg;
	void OutMsg();
	void ReadMsgFromFile();
	void SaveMsgToFile();
	void InMsg();
	Mailman();
	virtual ~Mailman();
private:
	char Buf[1024];
	fstream fs;
};
Mailman::Mailman()
{
	cout<<"Mail man working!"<<endl;
	bHaveMsg=false;
}
Mailman::~Mailman()
{
	cout<<"Mail man leaving..."<<endl;
}
void Mailman::OutMsg()
{
	if(Buf[0]!='\0')
	{
		cout<<"-------Here is your message------"<<endl;
		cout<<Buf;
		cout<<"-------------End------------"<<endl;
	}
	else
	{
		cout<<"\n---------No message-------"<<endl;
	}
}
void Mailman::InMsg()
{
	char temp;
	cin.unsetf(ios::skipws);
	cout<<"\nPlease input your message,end with\"~\"(shift`):"<<endl;
	for(int i=0;i<1024;i++)
	{
		cin>>temp;
		Buf[i]=temp;
		if(temp=='~')
		{
			Buf[i]='\0';
			break;
		}
	}
}      
void Mailman::SaveMsgToFile()
{
	fs.open("c:\\message.in",ios::out);
	fs<<Buf;
	fs.close;
	cout<<"\nmessage saved to file."<<endl;
	return ;
}
void Mailman::ReadMsgFromFile()
{
	fs.open("c:\\message.ini",ios::in);
	char temp;
	fs.unsetf(ios::skipws);
	for(int i=0;i<1024;i++)
	{
		if(fs>>temp)
		{
			Buf[i]=temp;
		}
		else
		{
			Buf[i]='\0';
			break;
		}
	}
	fs.close();
}
class abc
{
	int i;
	double d;
	float f;
public:
	abc();
	friend ostream & operator<<(ostream &s,abc x);
};
abc::abc()
{
	i=999;
	d=-100;
	f=9.0;
}
ostream & operator<<(ostream &s,abc x)
{
	cout.setf(ios::hex);
	cout<<x.i<<endl<<endl;
	cout.unsetf(ios::hex);
	cout.width(15);
	cout.setf(ios::fixed);
	cout.precision(6);
	cout.fill('$');
	cout<<x.d<<endl<<endl;
	cout.width(20);
	cout.fill('@');
	cout.precision(4);
	cout.setf(ios::showpos);
	cout<<x.f<<endl;
	return s;
}
void main()
{
	abc e;
	cout<<e<<endl;
	Mailman *p=new Mailman();
	p->ReadMsgFromFile();
	p->OutMsg();
	p->InMsg();
	p->SaveMsgToFile();
	delete p;
	return ;
}
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -