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 ...
随机推荐
- org.apache.commons.httpclient和org.apache.http.client区别(转)
官网说明: http://hc.apache.org/httpclient-3.x/ Commons HttpClient项目现已结束,不再开发.它已被其HttpClient和HttpCore模块中的 ...
- 2015 Noip提高组 Day2
P2678 跳石头 [题目背景] 一年一度的“跳石头”比赛又要开始了! [题目描述] 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和 ...
- 三、python的基本类型
一.number 整数 int 浮点数 float 1.type()查看类型 >>> type(1) <class 'int'> >>> type(1. ...
- 关于spring的简概
一.Spring入门操作 IOC 创建对象 <bean id="user" class="com.itheima.domain.User">< ...
- Python简易购物车程序
2019年5月24日,是我离开北京回学校的日子.我退了组的房子,辞了工作,带着对小秋香不舍回家,这匆匆一别,不知何时才是归期. 这几天都疏于学习,因为每一天我都会和她找点有意思的事情来做,如果这一别就 ...
- C 语言实例 - 阶乘
C 语言实例 - 阶乘 一个正整数的阶乘(英语:factorial)是所有小于及等于该数的正整数的积,并且0的阶乘为1.自然数n的阶乘写作n!. n!=×××...×n.阶乘亦可以递归方式定义:!=, ...
- JavaScript进阶 - 第9章 DOM对象,控制HTML元素
第9章 DOM对象,控制HTML元素 9-1 认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属 ...
- JavaScript进阶 - 第3章 一起组团(数组)
第3章 一起组团(数组) 3-1 一起组团(什么是数组) 我们知道变量用来存储数据,一个变量只能存储一个内容.假设你想存储10个人的姓名或者存储20个人的数学成绩,就需要10个或20个变量来存储,如果 ...
- python 7 dict和set
dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...
- [代码修订版] Python 踩坑之旅 [进程篇其四] 踩透 uid euid suid gid egid sgid的坑坑洼洼
目录 1.1 踩坑案例 1.2 填坑解法 1.3 坑位分析 1.4 技术关键字 1.5 坑后思考 下期坑位预告 代码示例支持 平台: Centos 6.3 Python: 2.7.14 代码示例: 公 ...