拼命流血

拼命流血

C++博客 首页 新随笔 联系 聚合 管理
  8 Posts :: 22 Stories :: 3 Comments :: 0 Trackbacks
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;

}
posted on 2006-02-22 16:28 拼命流血 阅读(663) 评论(0)  编辑 收藏 引用 所属分类: 技术类

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理