读取和写入Ini文件 [英] Reading and Writing to Ini Files

查看:79
本文介绍了读取和写入Ini文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的新手,并且继承了一些可读取和写入注册表的C ++程序.现在看来,他们不想使用注册表.因此,他们想读取和写入文件.建议使用Ini文件.我尝试了一些代码,但是没有创建文件.这是我尝试的代码:

I am new to c++ and have inherited few c++ programs that read and write to the registry. Now it seems that they do not want to utilise the registry. Therefore they want to read and write to files. Ini files were suggested. I tried some code but no file gets created. Here is the code that I tried:

TIniFile *StartUp = new TIniFile("privs.ini");

Left = StartUp->ReadInteger("FormPos", "Left", 250);
Top = StartUp->ReadInteger("FormPos", "Top", 200);

delete StartUp;


谁能告诉我为什么不创建文件?


Can anyone tell me why no file is created?

推荐答案



我认为您的代码没有错.您确定未创建文件吗?也许它不在您期望的位置?!

您可以查看此链接以获取更多信息:
http://www.ww.functionx.com/bcb/howto/inifile.htm [ ^ ]
Hi,

I see nothing wrong with your code. Are you sure that the file is not created? Maybe it just is not at the location you expect it to be?!

You could see this link for more information:
http://www.ww.functionx.com/bcb/howto/inifile.htm[^]


JF2015绝对是正确的轨道.

为您的ini文件使用完整路径.现在的操作方式,可能意味着它最终在Windows目录中.

更新:

JF2015 is definitely on the right track.

Use full path for your ini file. The way you do it now, probably means it ended up in the windows directory.

Update:

TIniFile *StartUp = new TIniFile("c:\\path\\to\\inifile\\privs.ini");

// get value or default if not found
Left = StartUp->ReadInteger("FormPos", "Left", 250); 
Top = StartUp->ReadInteger("FormPos", "Top", 200);

// Write to the ini file
StartUp->WriteInteger("FormPos", "Top", Top); 
StartUp->WriteInteger("FormPos", "Left", Left);

// Flush changes
StartUp->UpdateFile()



调用UpdateFile刷新从INI文件到磁盘的缓冲读取和写入. UpdateFile在Windows9x下很有用,但在Windows NT下不起作用,因为NT不会缓冲INI文件的读写.
仅当应用程序针对Windows编译时,此版本的UpdateFile才可用.
问候
Espen Harlinn



Call UpdateFile to flush buffered reads from and writes to the INI file to disk. UpdateFile is useful under Windows9x, but has no effect under Windows NT because NT does not buffer INI file reads and writes.

This version of UpdateFile is only available if the application is compiled for Windows

Regards
Espen Harlinn


希望 INI文件 [ ^ ]会给出你一个主意.
Hope INI FILES[^] will give you an idea.


这篇关于读取和写入Ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆