首页 > 其他分享 >daka

daka

时间:2023-05-18 20:33:09浏览次数:34  
标签:info daka ifstream ifs ServerInfo configfile include

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<bits/stdc++.h>

using namespace std;

struct ServerInfo
{
    char _ip[32];
    int _port;
 } ;
 
 struct ConfigManager
 {
     public:
         ConfigManager(const char* configfile = "bitsserver.config")
             :_configfile(configfile)
             {
             }
        void WriteBin(const ServerInfo& info)
        {
            ofstream ofs(_configfile, ifstream::out | ifstream::binary);
            ofs.write((const char*)&info, sizeof(ServerInfo));
            ofs.close();
        }
        void ReadBin(ServerInfo& info)
        {
            ifstream ifs(_configfile, ifstream::in | ifstream::binary);
            ifs.read((char*)&info, sizeof(ServerInfo));
            ifs.close();
        }
        
        void WriteText(const ServerInfo& info)
        {
            ofstream ofs(_configfile);
            ofs << info._ip << endl;
            ofs << info._port << endl;
            ofs.close();
        }
        void ReadText(ServerInfo& info)
        {
            ifstream ifs(_configfile);
            ifs >> info._ip;
            ifs >> info._port;
            ifs.close();
        }
    private:
        string _configfile;    
    
 };
 int main()
 {
     ConfigManager cfgMgr;
     ServerInfo wtinfo;
     ServerInfo rdinfo;
     strcpy(wtinfo._ip, "127.0.0.1");
     wtinfo._port = 80;
     
     cfgMgr.WriteText(wtinfo);
     cfgMgr.ReadText(rdinfo);
     cout << rdinfo._ip << endl;
     cout << rdinfo._port << endl;
     
     cfgMgr.WriteBin(wtinfo);
     cfgMgr.ReadBin(rdinfo);
     cout << rdinfo._ip << endl;
     cout << rdinfo._port << endl; 
     
     return 0;    
 }
 

 

标签:info,daka,ifstream,ifs,ServerInfo,configfile,include
From: https://www.cnblogs.com/kongxiangzeng/p/17413222.html

相关文章

  • daka :p
    6-2数组排序输出(函数模板)分数 10全屏浏览题目切换布局作者 何振峰单位 福州大学对于输入的每一批数,按从小到大排序后输出。一行输入为一批数,第一个输入为数据类型(1表示整数,2表示字符型数,3表示有一位小数的浮点数,4表示字符串,0表示输入结束),第二个......
  • daka :p
     2.设计思路①依次列举出所有0~9的两位相同数字②在第一步的前提下依次列举出0~9的两位相同数字③将第一第二步中的四个数字组成的数进行开根,判断结果是否为整数后输出结果 #include<bits/stdc++.h>usingnamespacestd;intmain(){inti,j,k,temp;for......
  • daka :p
      #include<bits/stdc++.h>#defineN10usingnamespacestd;main(){inti,j,a[N],t,count=0;printf("ÇëΪÊý×éÔªËظ³³õÖµ£º\n");for(i=0;i<N;i++)scanf("%d",&a[i]);for(i=1;i<=N-1;i++)......
  • daka :p
    #incldude<bits/stdc++.h>usinggnamespacestd;intmain(){inti,j,x,flag=0;for(i=23;flag==0;i++){for(j=1,x=i;j<=4&&x>=11;j++){if((x+1)%(j+1)==0)x-=......
  • daka :p
     #include<bits/stdc++.h>usingnamespacestd;intmain(){intm,n,number=0;for(m=0;m<=3;m++){for(n=0;n<=3;n++){if(8-m-n<=6)number++;}}cout<<......
  • daka :p
    复数类Complex有两个数据成员:a和b,分别代表复数的实部和虚部,并有若干构造函数和一个重载-(减号,用于计算两个复数的距离)的成员函数。要求设计一个函数模板template<classT>doubledist(Ta,Tb)对int,float,Complex或者其他类型的数据,返回两个数据的间距。以上类名和函数模......
  • daka :p
     #include<bits/stdc++.h>usingnamespacestd;voidprint(ints[]);intjudge(intc[]);intj=0;intmain(){ intsweet[10]={10,2,8,22,16,4,10,6,14,20}; inti,t[10],l; printf("child12345678910\n"); printf......