c++ builder ini文件读写

本文演示了如何使用TIniFile类来读写INI文件。通过实例展示了创建INI文件并进行字符串、整数、浮点数及布尔值的读写操作。此教程适用于需要配置存储的应用开发场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <inifiles.hpp>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{    //TIniFile *pIniFile = new TIniFile(ExtractFilePath(Application->ExeName)+"myTest.ini");//
     TIniFile *pIni = new TIniFile("c:\\myTest.ini");//
     pIni->WriteString("张三","籍贯","重庆");
     pIni->WriteInteger("张三","年龄",18);
     pIni->WriteFloat("张三","体重",60.5);
     pIni->WriteBool("张三","婚否",false);
     pIni->WriteString("李四","籍贯","江西");
     pIni->WriteInteger("李四","年龄",23);
     pIni->WriteFloat("李四","体重",63);
     pIni->WriteBool("李四","婚否",true);

     AnsiString str1;
     AnsiString old;
     float weight;
     bool IsMarried;
     std::cout<<"张三:" <<std::endl;
     str1=pIni->ReadString("张三","籍贯","未知");cout<<str1<<endl;
     old=pIni->ReadInteger("张三","年龄",0);cout<<old<<endl;
     weight=pIni->ReadFloat("张三","体重",0);cout<<weight<<endl;
     IsMarried=pIni->ReadBool("张三","婚否",false);cout<<IsMarried<<endl;
     cout<<"李四:" <<endl;
     str1=pIni->ReadString("李四","籍贯","未知");cout<<str1<<endl;
     old=pIni->ReadInteger("李四","年龄",0);cout<<old<<endl;
     weight=pIni->ReadFloat("李四","体重",0);cout<<weight<<endl;
     IsMarried=pIni->ReadBool("李四","婚否",false);cout<<IsMarried<<endl;
     delete pIni;
     system("pause");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值