在C程序中保存数据的位置 [英] Where to save data in C program

查看:91
本文介绍了在C程序中保存数据的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我必须编写一个C ++程序来保存用户设置

使用不是管理员权限而无法保存在安装文件夹中

什么是保存数据的正确位置



我尝试了什么:



我试着保存到temp文件夹,但数据随机被删除

如何停止删除数据?

Hello I have to write a C++ program to save user setting
Use is not admin rights and can not save in install folder
What is correct place to save data

What I have tried:

I try to save to temp folder but data get deleeted random times
How to stop deleting data?

推荐答案

Windows为此类数据提供特殊文件夹。要使用的文件夹取决于数据的类型(特定于用户或特定于应用程序)。



使用 SHGetKnownFolderPath函数(Windows) [ ^ ]获取此类文件夹的路径并附加应用程序的名称。在第一次创建文件夹之前存储数据之前。



根据您的数据类型,可以使用这些文件夹ID(参见KNOWNFOLDERID(Windows) [ ^ ]获取完整列表):



每位用户(其他人无法访问)用户)



FOLDERID_Documents %USERPROFILE%\Documents

适用于您的应用程序创建的个人文档。



FOLDERID_LocalAppData %USERPROFILE% \ AppData \本地

用于特定用户的应用数据(例如设置)。



FOLDERID_RoamingAppData %USERPROFILE%\ AppData \Roaming

如上所述,但对于域登录帐户(登录多个时共享的数据)系统)。



对于al l用户



FOLDERID_ProgramData

适用于系统级应用程序数据。



FOLDERID_PublicDocuments

适用于您的应用程序创建的公共(共享)文档。
Windows provides special folders for such data. The folder to be used depends on the type of the data (user specific or app specific).

Use the SHGetKnownFolderPath function (Windows)[^] to get the path for such folders and append the name of your application. Before storing data the first time you must create the folder.

Depending on your type of data, these folder IDs may be used (see KNOWNFOLDERID (Windows)[^] for a complete list):

Per user (not accessible by other users)

FOLDERID_Documents (%USERPROFILE%\Documents)
For personal documents created by your application.

FOLDERID_LocalAppData (%USERPROFILE%\AppData\Local)
For user specific application data (e.g. settings).

FOLDERID_RoamingAppData (%USERPROFILE%\AppData\Roaming)
As above but for domain login accounts (data shared when logged in on multiple systems).

For all users

FOLDERID_ProgramData
For system wide application data.

FOLDERID_PublicDocuments
For public (shared) documents created by your application.


这篇关于在C程序中保存数据的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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