cfg_file.h

来自「ears-0.32, linux下有用的语音信号处理工具包」· C头文件 代码 · 共 55 行

H
55
字号
#ifndef Cfg_file_h#define Cfg_file_h#include <string>#include <fstream.h>#include <stdio.h>class cfg_file{private:  char fn[256], tfn[256];  fstream fs;  bool first;public:  explicit cfg_file (const string& path)   : first(true)  {     strcpy(fn,path.c_str());    strcpy(tfn,fn);    strcat(tfn,".tmp");    fs.open(fn,ios::in);   }  ~cfg_file()  {    fs.close();    if (!first)    {      remove (fn);      rename (tfn,fn);    }  }    bool getpair (string& s1, string& s2)   {     char* p;    s1 = "";    fs >> s1 >> ws;    fs.gets (&p);    s2 = p ? p : "";    if (fs.eof() && s2.length()==0) return false;    return true;   }  bool exists() { return fs? true:false; }  void write (const string& s1, const string& s2)   {     if (first) { fs.close(); fs.open(tfn,ios::out|ios::trunc); first=false; }    fs << s1 << " " << s2 << endl;  }};#endif

⌨️ 快捷键说明

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