unsigned long Write_Ini_Value(string strFileName,string strKey,string strValue){
using namespace std;
std::list<std::string> text;
unsigned long ret_code=0;
const int READ_BUFFER_SIZE=1024;
char readBuffer[READ_BUFFER_SIZE]={0};
bool bFindKey=false;
string line;
//Find ini key and value
fstream rcFile(strFileName.c_str(), ios::in);
if(!rcFile){
ret_code=false;
goto EXIT_FUNCTION;
}
while(rcFile.getline(readBuffer,READ_BUFFER_SIZE,'\n')){
line=readBuffer;
if(line.empty()) continue;
if(line.length()<=strKey.length()){
text.push_back(line);
continue;
}
if(line.substr(0,strKey.length())==strKey){
text.push_back(strKey+"="+strValue);
bFindKey=true;
}else{
text.push_back(line);
continue;
}
}
rcFile.close();
if(bFindKey){
ofstream iniFile(strFileName.c_str());
if(!iniFile){
ret_code=false;
}else{
for(list<string>::iterator iter=text.begin();iter!=text.end();++iter){
iniFile << (*iter).c_str() << endl;
}
ret_code=true;
}
iniFile.close();
}
EXIT_FUNCTION:
return ret_code;
}