main.cpp
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define SELF_CHEK_FILE "1.ini"
using namespace std;
bool getPersonInfo()
{
int i=0;
char buf[500];
int fd = open(SELF_CHEK_FILE, O_RDWR ,0777);
if(fd<0)
{
return false;
}
if(-1 == read(fd,buf,sizeof(buf)))
return false;
char* tmp = strtok(buf, "=");
string str[3];
while(tmp)
{
tmp = strtok(NULL, "\r\n");
str[i] = tmp;
printf("str: %s\n", str[i].data());
if(i==3)
break;
tmp = strtok(NULL, "=");
i++;
}
close(fd);
return true;
}
int main()
{
getPersonInfo();
return 0;
}
1.ini
name=hxx
age=19
sex=womem