张小斐的男朋友叫什么linux配置⽂件如何写,linux读写配置⽂件#include "cstdio"
#include "iostream"
#include "string"
#include "fstream"
using namespace std;
int GetProfileString(string file_name, string section_name, string item_name,
string &item_value)
{
ifstream mystream ;
mystream.open(file_name.c_str(), ios::in);
if (!mystream)
{
cout << "Error " << endl;
return -1;
}
char line[30] = {0};
string line2;
string::size_type return_of_find;
bool found = false;
while (line(line, 30) && !found) //默认⾏不会超过30个字符
{
line2 = line;
return_of_find = line2.find(section_name);
if (string::npos == return_of_find)
continue; //没到section项,则继续下⼀⾏读取
女酷while (line(line, 30) && !found)读取配置文件失败
{
谈古论今的意思line2 = line;
string equal_flag = "=";
return_of_find = line2.find(equal_flag);
if (string::npos == return_of_find)
return -1;//说明已经跨越了多段,⽬标寻失败
/
/还在当前段中
return_of_find = line2.find(item_name);
if (string::npos == return_of_find)
continue; //没有到
//到了
return_of_find = line2.rfind(" "); //要求配置⽂件=两边要有空格
item_value = line2.substr(return_of_find + 1); //该⾏最后⼀个空格之后开始的为所要的item_value found = true;
个人所得税怎么申报}
}
mystream.close();
return 0;
}
发布评论