0

2 つのテキスト ファイルがあります。元の出力:

Log.txt
Joe hello
Joe gargabash
Joe random unnecessary text
Hello
How are you?

Log2.txt は、最初は空白の別のテキスト ファイルです。

このコードを実行すると、Joe で始まらないすべての行が正常にコピーされます。ただし、テキストを元の .txt にコピーしたいと考えています。コメントした選択をコメントアウトしてそれをしようとすると、エラーが発生します。私が間違っていることを知っている人はいますか?この混乱をすべて読んでくれてありがとう。明確にするために、bool STRINGCONTAINS(int, char, char, int) は、char 配列が別の char 配列と一致するかどうかをチェックします。

#include <WinSock2.h>
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>


using namespace std;

bool STRINGCONTAINS(bool CaseSensitive, //If this is true, we are checking a case sensitive string, if it's false, we're not.
                  char * input1, // First string [Type: Char Array]
                  char * input2, //Second String [Type: Char Array]
                  int MAXSTRINGLENGTH) // Integer representing max possible length of string.
{
    if (CaseSensitive) 
    {
        for(int i=0;i<MAXSTRINGLENGTH;i++) 
        {
            if (*input1 == *input2) 
            {
                input1++; 
                input2++; 
            } else
            {
                return 0;
            }
        } 
    } else 
    {
        int char1, char2; 
        for(int i=0;i<MAXSTRINGLENGTH;i++) 
        {
            char1 = *input1; 
            char2 = *input2; 
            if (char1 == char2 || char1 == (char2+32) || char2 == (char1+32)) 
            {

                input1++; 
                input2++; 
            } else 
            {
                return 0;
            }
        } 
    }
    return 1;
}


int main() {
    int input;
                    char * loadedline = new char[192];
                    ifstream log;
                    ofstream templog;
                    log.open("log.txt");
                    templog.open("log2.txt");
                    while(log.getline(loadedline,sizeof(log)))
                    {
                        if (!STRINGCONTAINS(0,loadedline,"joe",3))
                        {
                        cout << loadedline << endl;
                        templog << loadedline << endl;
                        }
                    }
                    log.close();
                    templog.close();
                    /*ifstream templog2;
                    ofstream log2;
                    templog2.open("log2.txt");
                    log2.open("log.txt");
                    while(templog2.getline(loadedline,sizeof(templog2)))
                    {
                        log2 << loadedline << endl;
                    }
                    templog2.close();
                    log2.close;*/
                    delete[] loadedline;
                    cin >> input;
                    return 0;
}
4

1 に答える 1