创建Ini文件 [英] Creation of Ini file

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

问题描述

我想通过编码创建一个ini文件.如果在应用程序路径上未找到ini文件,则应用程序本身将使用部分和名称创建ini文件.创建后,默认值将从代码中填充.在嵌入式Visual C ++中这可能吗?如果是,请告诉我并帮助我解决此问题.我的基本条件是用户永远不要创建ini文件,也永远不要更改该ini文件的字段. P 请帮助我.

I want to create an ini file through coding. If on application path ini file is not found then application itself create the ini file with the section and the name. And after creation the default value is filled from the code. Is this possible in embedded visual c++? If yes the tell me and help me to solve this problem. My basic condition is that user never create ini file and never change the field of that ini file.Do evething from the code. Please help me.

推荐答案

C#:
if (!System.IO.File.Exists("YourFileName.ini"))
{
    System.IO.File.Create("YourFileName.ini");
}




Visual C ++:




Visual C++ :

if (!File::Exists("YourFileName.ini"))
{
    File::Create("YourFileName.ini");
}


I create the ini file run time but whenever I write any value in the section using WriteProfileString() it requires the registry key.

CFile obFile;

if( obFile.Open( strAppIniPath, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite ))
{
        AfxMessageBox(_T("File Opened"),IDOK,NULL);
    bResult = theApp.WriteProfileString(_T("General"), _T("FirstName"), _T("String1"));
    bResult = theApp.WriteProfileString(_T("General"),_T("LastName"), _T("String2"));
}
else
{
    AfxMessageBox(_T("Unable to Open File"),IDOK,NULL);
}


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

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