日期:2014-05-16  浏览次数:20781 次

C++文件修改
配置文件密码修改


[bill]
username = xxxx
password = 1234455

现在要将密码改为 成新的字符串
就是先要定位到老密码的位置 再更新为新密码


------解决方案--------------------
一个易理解易编码,但不健状的解决方案

fistream sin(...读打开旧配置文件...);
fostream sout(..写打开一个新文件............);
char buf[SIZE];
while(sin.eof())
{
sin.getline(buf);
....
// 分析 ...处理...
sout << buf << endl;
}

删掉旧的

更名新的

基本上就是这样了.
------解决方案--------------------
一行一行读
处理
一行一行写.
------解决方案--------------------
不能直接在原来的
文件上修改???


-----------------------
如果你能保证密码长度是固定的,那时可以之间修改的.
------解决方案--------------------
C/C++ code

/* *
*@file             inifile.h
*@cpright        (C)2007 GEC 
*@auther        dengyangjun
*@email        dyj057@gmail.com
*@version        0.1
*@create         2007-1-14 
*@modify        2007-1-14
*@brief            declare ini file operation
*@note
*@history    
*/ 

#ifndef INI_FILE_H_
#define  INI_FILE_H_ 

#ifdef __cplusplus
extern   "C" 
{
#endif 

int  read_profile_string(  const   char   * section,  const   char   * key, char   * value,  int  size,  const   char   * file);
int  read_profile_int(  const   char   * section,  const   char   * key, int  default_value,  const   char   * file);

int  write_profile_string(  const   char   * section,  const   char   * key, const   char   * value,  const   char   * file);

#ifdef __cplusplus
};  // end of extern "C" { 
#endif 

#endif   // end of INI_FILE_H_

------解决方案--------------------
Linuxg可以直接修改文件数据的,Window下不可以。