CPP-基础:c++读取ini文件
配置文件格式是
[JP]
K=2EC156673E 2F4240 5595F6
char str[50];
GetPrivateProfileString("JP", "K",NULL, str, sizeof(str),".\\keydog.ini");
得到str后想将其分成三个字符串
str1=2EC156673E
str2=2F4240
str3=5595F6
第一种方法用MFC
得有这句#include <afx.h>和包含mfc库 CString sz;
GetPrivateProfileString("JP", "K", NULL, sz.GetBuffer(50), 50, "./keydog.ini");
sz.ReleaseBuffer();
int nPos = 0;
CString sz1, sz2, sz3;
sz1 = sz.Tokenize(" ", nPos);
sz2 = sz.Tokenize(" ", nPos);
sz3 = sz.Tokenize(" ", nPos); 第二种用标准c++
得#include <string> 和using std::string; string str(50, 0);
GetPrivateProfileString("JP", "K", NULL, (char*)str.c_str(), 50, "./keydog.ini");
string sz1, sz2, sz3;
int nBegin = 0, nEnd = str.find(' ', nBegin);
sz1 = str.substr(nBegin, nEnd - nBegin);
nBegin = nEnd + 1, nEnd = str.find(' ', nBegin);
sz2 = str.substr(nBegin, nEnd - nBegin);
nBegin = nEnd + 1, nEnd = str.find(' ', nBegin);
sz3 = str.substr(nBegin, nEnd - nBegin); 第三种纯c吧...
得#include <string.h> char str[50] = {0};
GetPrivateProfileString("JP", "K", NULL, str, sizeof(str),".\\keydog.ini");
char sz1[50] = {0}, sz2[50] = {0}, sz3[50] = {0};
sscanf( str, "%[^' ']", sz1);
sscanf( str + strlen(sz1) + 1, "%[^' ']", sz2);
sscanf( str + + strlen(sz1) + strlen(sz2) + 2, "%[^' ']", sz3); 再给个傻瓜版c代码吧, 因为str1等没有另外给空间, 看你怎么用了
#include <stdio.h>
#include <windows.h> int main()
{
char str[50], *str1, *str2, *str3;
GetPrivateProfileString("JP", "K",NULL, str, sizeof(str),".\\keydog.ini");
str2 = str1 = str;
while( ' ' != *++str2);
*str2++ = 0;
for( str3 = str2; ' ' != *++str3; );
*str3++ = 0; return 0;
}
CPP-基础:c++读取ini文件的更多相关文章
- Python基础之读取ini文件
基本使用方法 第一步:准备一份INI文件.如test1.ini [ITEMS] item1=1 item2=2 item3=3 item4=4 [ITEM1] test1=aaa [ITEM2] te ...
- C#读取ini文件的方法
最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using S ...
- VS VC 读取 INI文件
1.获取应程序同极目录下的config.ini路劲 void GetConfigFilePath(char *path,int len, char *file) { char module[256] ...
- C# 读取ini文件,读不出来原因
先赋上相关读取ini文件代码 public class INIHelper { public string inipath; [DllImport("kernel32")] pri ...
- C# 通过api函数GetPrivateProfileString读取ini文件,取不到值
通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...
- C# 读取ini文件 百度问问学习文档
C# 读取ini文件 10 有多个section,现想读取整个ini文件和指定section下所有内容 补充: 发布答案可以,请对准题目啊,我不要指定节点的内容,我知道!我要的是读取指定区域的内容,假 ...
- python中configparser模块读取ini文件
python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...
- bat 读取 ini 文件
bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-f ...
- java读取ini文件
ini工具类; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import j ...
- c#读取INI文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
随机推荐
- 将Angular6自己定义的模块发布成npm包
创建自己的模块组件 1. ng new 一个工程 2. ng g m 创建模块 例如我这里的modules文件下创建header模块 3. ng g c modules/head 创建一个hear组件 ...
- js实现考试随机选题
考试的时候经常用到,发在这里记录一下 基本信息包括: 学号.姓名.题号.题目名称 实现原理:给每一个题目添加一个编号,JS生成随机数,遍历每一个学生,把题目根据生成的随机数作为题目编号放入学生信息中 ...
- The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)(转)
Microsoft SQL Server 5030错误解决办法 今天在使用SQL Server时,由于之前创建数据库忘记了设置Collocation,数据库中插入中文字符都是乱码,于是到DataBas ...
- PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...
- Python内建函数二
内置函数二: 1.lambda (匿名函数) 为了解决一些简答的需求而设计的一句话函数.不需要def来声明. def func(n): return n*n f = lambda n: n*n 注意: ...
- js 创建方法
贴个代码先: function O(user,pwd){ //use constructor this.user=user; this.pwd=pwd; this.get=get; return th ...
- gedit配置
编辑 \(\rightarrow\) 首选项 \(\rightarrow\) 插件 \(\rightarrow\) 外部工具 启用 进入工具 \(\rightarrow\) Manage Extern ...
- Hive进阶_Hive数据查询
简单查询和fetch task 简单查询: 简单查询的 fetch task 功能,从HDFS拉取,不用map reduce. 前两种配置,当前session有效.修改hive-site.xml永 ...
- NET Core 模块化,多租户框架
NET Core 模块化,多租户框架 Orchard Core Framework:ASP.NET Core 模块化,多租户框架 上一篇编写Orchard Core一分钟搭建ASP.NET Core ...
- NET Core应用中如何记录和查看日志
NET Core应用中如何记录和查看日志 日志记录不仅对于我们开发的应用,还是对于ASP.NET Core框架功能都是一项非常重要的功能特性.我们知道ASP.NET Core使用的是一个极具扩展性的日 ...