软件保存复杂参数到文件的一个实例,容器相关

本人某个项目中的一部分代码,与大家分享。

Region是自己定义的一个类。

程序中定义了四个region容器对象:vector<Region> Reg[4];

在视频窗口画图的参数保存到上述容器中,下面程序实现参数保存到region.ini文件并可以程序启动

时读入这些参数。

class Region
{
public:
 int channel;
 int function;
 CPoint point1;
 CPoint point2;
 int graphType;
 COLORREF color;
// int state;
// bool bExist;

public:
 int Match();
 void DrawRegion();
 void DeleteRegion();
 void SaveRegion();
 void LoadRegion();
 Region();
    virtual ~Region();
};

 

CVideoWin::CVideoWin()
{
 m_bIsDraw = FALSE;

 FILE *stream;
 Region RegTmp;
 int assignedBits;
 int channel;
 stream = fopen( "region.ini", "r" );
    if( stream == NULL)
  return;
 else
 {
  fseek( stream, 0, SEEK_SET );
  while(1)
  {
   assignedBits = fscanf( stream, "%d", &channel );
   if( assignedBits != 1 )
   {
    fclose( stream );
    return;
   }
   RegTmp.channel = channel;
   fscanf( stream, "%d", &RegTmp.function );
   fscanf( stream, "%d", &RegTmp.point1.x );
   fscanf( stream, "%d", &RegTmp.point1.y );
   fscanf( stream, "%d", &RegTmp.point2.x );
   fscanf( stream, "%d", &RegTmp.point2.y );
   fscanf( stream, "%d", &RegTmp.graphType );
   fscanf( stream, "%d", &RegTmp.color );
   Reg[channel].push_back(RegTmp);
//   fclose( stream );
  }
 }

}

 


 CVideoWin::~CVideoWin()
{
 int i,j;
 Region RegTmp;
 FILE* stream;
 stream = fopen( "region.ini","w+" );
 fclose(stream);
 for(i=0;i<4;i++)
  for(j=0;j<Reg[i].size();j++)
  {
   RegTmp = Reg[i].at(j);
   RegTmp.SaveRegion();
  }
}

  void Region::SaveRegion()
{
 FILE *stream;
 stream = fopen( "region.ini","a" );
 fprintf( stream,"%d/n%d/n%d/n%d/n%d/n%d/n%d/n%d/n",
          channel,function,point1.x,point1.y,point2.x,point2.y,graphType,color );
 fclose( stream );

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值