case: 对已有的配置文件common.conf,内容如下:
begin.timestamp=1262275200
end.timestamp=1338434912
程序每运行完一次,需要将begin.timestamp和end.timestamp进行修改,暂定后面字符串长度一样。
代码:
FILE * pFile = NULL;
pFile = fopen ( filename , "r+" );//注意这里文件打开方式,如果是"w',则总出现问题,查看手册说明有何区别即可
if(pFile == NULL)
{
return false;
}
fseek ( pFile , strlen("begin.timestamp=") , SEEK_SET );
fputs ( begin_timestamp.c_str() , pFile );
fseek ( pFile , strlen("end.timestamp=")+1 , SEEK_CUR );//多了一个\n符
fputs ( end_timestamp.c_str() , pFile );
fclose ( pFile );