文件读写的问题:怎样读入一行并且写入一行字符串??
文件读写的问题:怎样读入一行并且写入一行字符串??
FILE *fp;
CString strPathName = "E:\\cstrike\\config99.CFG";
fp = fopen(strPathName,"r+");
char line[255];
CString strTemp = "";
if( fp )
{
while( !feof( fp ) )
{
char *ch = fgets( line, 1024, fp );//读一行
CString strTemp = (CString)ch;
if( strTemp == "abc" ) //如果这行的字符等于abc,则把这行替换
{ //为hello
fputs( "hello", fp );
}
}
}
fclose(fp);
我的问题是:我要读入E:\\cstrike\\config99.CFG这个文件,逐行读入,然后判断如果读入的这行为
“abc”,则替换为"hello",我现在用fgets函数已经能够逐行读入,但是不能用fputs函数把这行给替换掉,请问该怎么替换??谢谢!!