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

📄 14-7.cpp

📁 为初学者提供的最佳的C++程序设计源程序库
💻 CPP
字号:
#include<iostream.h>
#include<fstream.h>
class three_d
{
  int x,y,z;
public:
  three_d(int i,int j,int k){x=i;y=j;z=k;}
  friend ostream& operator<<(ostream& stream,three_d ob);
  friend istream& operator>>(istream& stream,three_d ob);
};
ostream& operator<<(ostream& stream,three_d ob)
{
  stream<<ob.x<<' '<<ob.y<<' '<<ob.z<<'\n';
  return stream;
}
istream& operator>>(istream& stream,three_d  ob)
{
  stream>>ob.x>>ob.y>>ob.z;
  return stream;
}
main()
{
  three_d o1(1,2,3),o2(4,5,6);
  ofstream out("test");
  if(!out)
  {
    cout<<"Cannot open output file\n";
	return 1;
  }
  cout<<o1<<o2;
  out.close();
  ifstream in("test");
  if(!in)
  {
    cout<<"Cannot open input file\n";
	return 1;
  }
  three_d o3(0,0,0),o4(0,0,0);
  in>>o3>>o4;
  return 0;
}

⌨️ 快捷键说明

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