程序很小,不想用Access
用txt,好像过于简单了一点
Excel可以吗?有没有人试过?要够简单哦,因为数据不是程序员来编辑和维护的
用txt,好像过于简单了一点
Excel可以吗?有没有人试过?要够简单哦,因为数据不是程序员来编辑和维护的
解决方案 »
- 调用RichEdit的SetSelectionCharFormat为何会改别别的变量?
- 高分求教ms xml解析,很有难度哦,高手进!
- 怎么判断一个矩形是否在一个圆内(或圆外),
- vc2010 下 _set_se_translator 有bug?
- 帮忙,急。我要做的程序连接的数据库需要文件支持,但我的这个数据库文件可能
- 哪里有报表之类的东西啊?大恩不言谢,那就来领分吧。
- 关于对话框中弹出对话框的问题
- 请给我一个在CTreeCtrl中查找节点的算法
- 如何制作一个"透明"的窗口?
- 在项目中写通讯这一块,自己定的数据包感觉不理想,大家有什么好的包体设计?
- 打开数据库连接问题(ADO)!
- 请问:ActiveMovieControl Object控件在哪里?
各式如下:[section]
var1=value1
var2=value2有一套API函数可以直接访问ini文件:WriteProfileString,GetProfileString等,具体查msdn根据你的需要其实txt也挺好的,简单难道还不好吗?你完全可以自己定义格式,改变文件后缀
BOOL WritePrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpString, // string to add
LPCTSTR lpFileName // initialization file
);
UINT GetPrivateProfileInt(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
INT nDefault, // return value if key name not found
LPCTSTR lpFileName // initialization file name
);
DWORD GetPrivateProfileString(
LPCTSTR lpAppName, // section name
LPCTSTR lpKeyName, // key name
LPCTSTR lpDefault, // default string
LPTSTR lpReturnedString, // destination buffer
DWORD nSize, // size of destination buffer
LPCTSTR lpFileName // initialization file name
);
在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下: 一.将信息写入.INI文件中. 1.所用的WINAPI函数原型为: BOOL WritePrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpString,
LPCTSTR lpFileName
); 其中各参数的意义: LPCTSTR lpAppName 是INI文件中的一个字段名. LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名. LPCTSTR lpString 是键值,也就是变量的值,不过必须为LPCTSTR型或CString型的. LPCTSTR lpFileName 是完整的INI文件名. 2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:\stud\student.ini 文件中. CString strName,strTemp;
int nAge;
strName="张三";
nAge=12;
::WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini"); 此时c:\stud\student.ini文件中的内容如下: [StudentInfo]
Name=张三 3.要将学生的年龄保存下来,只需将整型的值变为字符型即可:strTemp.Format("%d",nAge);
::WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini");
二.将信息从INI文件中读入程序中的变量. 1.所用的WINAPI函数原型为:DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
); 其中各参数的意义: 前二个参数与 WritePrivateProfileString中的意义一样. lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量. lpReturnedString : 接收INI文件中的值的CString对象,即目的缓存器. nSize : 目的缓存器的大小. lpFileName : 是完整的INI文件名. 2.具体使用方法:现要将上一步中写入的学生的信息读入程序中.CString strStudName;
int nStudAge;
GetPrivateProfileString("StudentInfo","Name","默认姓名",strStudName.GetBuffer(MAX_PATH),MAX_PATH,"c:\\stud\\student.ini"); 执行后 strStudName 的值为:"张三",若前两个参数有误,其值为:"默认姓名". 3.读入整型值要用另一个WINAPI函数: UINT GetPrivateProfileInt(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
INT nDefault,
LPCTSTR lpFileName
); 这里的参数意义与上相同.使用方法如下:nStudAge=GetPrivateProfileInt("StudentInfo","Age",10,"c:\\stud\\student.ini");
三.循环写入多个值,设现有一程序,要将最近使用的几个文件名保存下来,具体程序如下: 1.写入:CString strTemp,strTempA;
int i;
int nCount=6;
file://共有6个文件名需要保存
for(i=0;i {strTemp.Format("%d",i);
strTempA=文件名;
file://文件名可以从数组,列表框等处取得.
::WritePrivateProfileString("UseFileName","FileName"+strTemp,strTempA,
"c:\\usefile\\usefile.ini");
}
strTemp.Format("%d",nCount);
::WritePrivateProfileString("FileCount","Count",strTemp,"c:\\usefile\\usefile.ini");
file://将文件总数写入,以便读出. 2.读出:nCount=::GetPrivateProfileInt("FileCount","Count",0,"c:\\usefile\\usefile.ini");
for(i=0;i {strTemp.Format("%d",i);
strTemp="FileName"+strTemp;
::GetPrivateProfileString("CurrentIni",strTemp,"default.fil", strTempA.GetBuffer(MAX_PATH),MAX_PATH,"c:\\usefile\\usefile.ini");file://使用strTempA中的内容.} 补充四点: 1.INI文件的路径必须完整,文件名前面的各级目录必须存在,否则写入不成功,该函数返回 FALSE 值. 2.文件名的路径中必须为 \\ ,因为在VC++中, \\ 才表示一个 \ . 3.也可将INI文件放在程序所在目录,此时 lpFileName 参数为: ".\\student.ini".