CPP-基础:c++读取ini文件
2024-10-15 23:59:38
配置文件格式是
[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;
}
最新文章
- 解决cookie跨域访问
- C#:调用webservice时提示对操作的回复消息正文进行反序列化时出错
- 利用libpcap打印ip包
- 防止SVN冲突,Elipse资源同步介绍
- POJ(3468)
- 通过PowerShell获取TCP响应(类Telnet)
- H5实现拍照并上传
- centos设置开机自启动
- web.xml常用标签整理(不定期更新)
- UC浏览器开发者版调试手机页面
- poj 3422 Kaka&#39;s Matrix Travels 费用流
- java数据类型,hibernate数据类型,标准sql数据类型之间的对应表
- Python实战之正则表达式RE/re学习笔记及简单练习
- LeetCode(49)-Valid Parentheses
- Linux文件系统的基本结构
- codeforces gym #102082C Emergency Evacuation(贪心Orz)
- mysql数据表的基本操作
- pycharm中代码整体缩进
- Oracle分区表常见操作
- 基于html5背景图片自适应代码