将配置写入文件 [英] Writing configurations to a file

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

问题描述

您好我正在编写一个应用程序,可能需要存储进程用户的设置/首选项。

我感兴趣的是通常的方法是什么?我假设我会在文件中存储首选项

。通常怎么做?哪种方法等

Hi I am writing an app, which may need to store process user''s settings/preferences.
I am interested what is the common way to do it? I assume I will store the preferences
in files. How it is done usually? Which methods etc.

推荐答案

常用方法使用 XML 文件(通常通过 XML 库,例如 MSXML [ ^ ])。旧式应用程序仍然使用 INI 文件。另一种方法是序列化 [ ^ ](如果您使用 MFC ,那么您可能会发现序列化得到很好的支持)。
A common approach uses XML files (usually via a XML library, like for instance MSXML[^] ). Old fashioned applications still use INI files. Another method is serialization[^] (if you are using MFC then you may find serialization is nicely supported).


解决方案#1对于配置数据的内部格式是正确的,但是没有说放在哪里。我建议像%HOMEDRIVE %% HOMEPATH%\ AppData \yourapp \ prefs.xml之类的东西。您的应用应该知道该文件存在时应该怎么做或应用程序启动时不应该知道该做什么。如果您的应用程序很复杂或需要不同的配置文件格式,请使用多个文件。
Solution #1 is correct for internal format of your config data, but doesn''t say where to put it. I suggest something like %HOMEDRIVE%%HOMEPATH%\AppData\yourapp\prefs.xml or something similar. Your app should know what to do if the file exists or does not when the app starts. If your app is complex or needs different config file formats, then use multiple files.


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

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