寻源代码(存取.ini文件)

anrxhzh 2002-07-16 11:38:46
要求:
1.跨平台
2.支持Windows INI文件格式
3.可读可写
4.最好是C++代码,C代码次之
5.Free
...全文
74 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
招RD和QA 2002-07-20
  • 打赏
  • 举报
回复
gzer
backin 2002-07-18
  • 打赏
  • 举报
回复
看不懂啊,看来应该好好加强基础知识的学习。
huangwu007 2002-07-18
  • 打赏
  • 举报
回复
以前就发过一次了,自己去看吧
http://www.csdn.net/expert/topic/585/585891.xml?temp=.9372522
LeeMaRS 2002-07-18
  • 打赏
  • 举报
回复
你强! 偶PF的说!
anrxhzh 2002-07-18
  • 打赏
  • 举报
回复
又是一个自问自答的帖子。
如果喜欢这个帖子的话,就请up,好让我结贴,谢了。
softman_2000 2002-07-16
  • 打赏
  • 举报
回复
谢谢。
lj_csdn 2002-07-16
  • 打赏
  • 举报
回复
只有一个读的
int GetPrivateProfileString(char *appname,char *keyname,char *Default,char *ret,int nsize,char *ininame)
{ FILE *fp;
char *ps,*p,s[256],ss[32];
strncpy(ret,Default,nsize);
ret[nsize-1]=0;
fp=fopen(ininame,"rt");
if (fp==NULL) return 0;
sprintf(ss,"[%s]",appname);
while (1)
{ if (fgets(s,256,fp)==NULL) { fclose(fp); return 0; }
if (strncmp(s,ss,strlen(ss))==0) break;
}
sprintf(ss,"%s=",keyname);
while (1)
{ if (fgets(s,256,fp)==NULL) { fclose(fp); return 0; }
if (strncmp(s,ss,strlen(ss))==0) break;
}
p=strchr(s,'=');
p++;
ps=p;
while ((*p)&&(*p!=' ')&&(*p!=10)&&(*p!=13)) p++;
*p=0;
strncpy(ret,ps,nsize);
ret[nsize-1]=0;
fclose(fp);
return strlen(ps);
}
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
找到了。不敢独享,分之:
http://home.pages.at/kingleo/development/cpp-en.html

LeoIni (C) under the terms of the GPL by King Leo (Martin Oberzalek)

LeoIni - Ini file reader

LeoIni is a class for easy reading ini files.

It can read Windows(TM) ini, KDE and GNOME ini files.
eg.: example/test-date.ini

The class is full ansi C++ compatible.
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
谢谢。TIniFile 的功能的确强,可惜不是标准C\C++,只能在Borland的平台上编译,并且不是Freeware。

我找到的Leoini是很出色的代码,都是VC闹的不痛快,VC有四五处不合标准,导致我在人家的代码上画蛇添足。哎,就快添完了:-)
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
谢谢。TIniFile 的功能的确强,可惜不是标准C\C++,只能在Borland的平台上编译,并且不是Freeware。

我找到的Leoini是很出色的代码,都是VC闹的不痛快,VC有四五处不合标准,导致我在人家的代码上画蛇添足。哎,就快添完了:-)
hbxtx 2002-07-16
  • 打赏
  • 举报
回复
别人的代码,你看看:
//读
String FilePath = ExtractFilePath( ParamStr( 0 ) );
TIniFile * IniFile;
IniFile = new TIniFile( FilePath + String( "sys_config.ini" ) );
Edit1->Text = IniFile->ReadString( "set", "servername", "" );
Edit2->Text = IniFile->ReadString( "set", "databasename", "" );
Edit3->Text = IniFile->ReadString( "set", "username", "" );
Edit4->Text = IniFile->ReadString( "set", "userpsw", "" );

//写
String FilePath = ExtractFilePath( ParamStr( 0 ) );
TIniFile * IniFile;
IniFile = new TIniFile( FilePath + String( "sys_config.ini" ) );
IniFile->WriteString("set","servername",Edit1->Text);//服务器名
IniFile->WriteString("set","databasename",Edit2->Text);//数据库名
IniFile->WriteString("set","username",Edit3->Text);//用户名
IniFile->WriteString("set","userpsw",Edit4->Text);//用户密码
delete IniFile;
Application->MessageBox("配置文件保存成功!","提示",MB_OK+MB_ICONINFORMATION);

头文件:
#include "inifiles.hpp"
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
应该是这样,否则会出乱子。真烦。

struct test {
typedef std::list<test> l;
std::auto_ptr<l> _M_l;

test()
: _M_l(new l)
{ }

};
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
看来只能这样了,别扭:

struct test {
typedef std::list<test> l;
test():_M_l(new l){}
~test(){delete l;}
l* _M_l;
};
anrxhzh 2002-07-16
  • 打赏
  • 举报
回复
气人的 Microsoft Visual C++ ,不支持这样的语法:
struct test {
typedef std::list<test> l;
l _M_l;
};
导致了Leoini编译不过。奈何,苦哇,谁来支招?

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧