wxWidgets读配置文件代码

来源:互联网 发布:ubuntu中的火狐浏览器 编辑:程序博客网 时间:2024/06/10 00:59
  1. wxString path_cfg(_("./config/record.conf")); //录音配置文件路径
  2. if(!wxFileExists(path_cfg))
  3. {
  4. wxMessageBox(_T("Can not find record.conf file"),_T("ERROR"));
  5. return ;
  6. }
  7. wxTextFile wxfile(path_cfg);
  8. wxfile.Open();
  9. wxString sum_row_str = _(""); //存放配置文件中的每行
  10. for (sum_row_str=wxfile.GetFirstLine(); !wxfile.Eof(); sum_row_str=wxfile.GetNextLine())
  11. {
  12. if(sum_row_str == _("[record]"))
  13. {
  14. while(!wxfile.Eof())
  15. {
  16. sum_row_str = wxfile.GetNextLine();
  17. wxString left_row_str = _(""); //每行等号左边内容
  18. wxString right_row_str = _(""); //每行等号右边内容
  19. for(int i = 0; i < sum_row_str.size(); i++)
  20. {
  21. if('[' == sum_row_str.at(i))
  22. {
  23. return ;
  24. }
  25. if(sum_row_str.at(i) == '=')
  26. {
  27. left_row_str = sum_row_str.SubString(0,i-1);
  28. right_row_str = sum_row_str.SubString(i+1,sum_row_str.size());
  29. }
  30. }
  31. wxString var_str; //变量字符串
  32. for(int j = 0; j < left_row_str.size(); j++)
  33. {
  34. if(' ' != left_row_str.at(j))
  35. {
  36. var_str = left_row_str.SubString(0,j); //把左边的变量切出来

  37. }

  38. }
  39. wxString val_str; //变量对应的值
  40. for(int k = 0; k < right_row_str.size(); k++)
  41. {
  42. if(' ' == right_row_str.at(k))
  43. {
  44. val_str = right_row_str.substr(k+1); //把右边的变量切出来
  45. }
  46. }
  47. if(var_str != "")
  48. {
  49. conf_map.insert(std::make_pair(var_str,val_str));//存放配置文件内容

  50. }
  51. }
  52. }

  53. if(wxfile.Eof())
  54. {
  55. return ;
  56. }
  57. }
  58. wxfile.Close();
0 0
原创粉丝点击