0

「すべてを検索して置換」を実装しようとしています。文字を監視するための2つのポインターがありますnclude #include #include名前空間stdを使用します。

const int BUFSIZE = 256;

const char * const SEARCH = "the";
const char * const REPLACE = "Who is John";

int main()
{
    char buf[BUFSIZE];
      Error(SOURCE_FILE);

    //open file for append and update
    fstream destination(DESTINATION_FILE, 
        ios_base::in | ios_base::out | ios_base::app);

    //check if destination file is open
    if (!destination.is_open())
        Error(SOURCE_FILE);


        bufPtr += length;               //move bufPtr to point past the SEARCH

        destination << bufPtr;          //write rest of buf to destination
        //destination.seekg(0);

        //write lines from source to destination
        //if(!(destination << buf << '\n'))
            //Error(SOURCE_FILE);
    }   
    source.close();
    destination.close();

    return 0;
}
4

1 に答える 1

2

strstr()検索文字列が見つからない場合をチェックしていません。その場合は戻りますがNULL、その場合、while ループ ループは正しいことを行いません。

于 2012-08-27T04:18:05.860 に答える