Trying to split a text file into multiple text files in C++
<p>I am trying to get this code to split an input file into two files. I want the code to split so that one new file contains all the odd characters and the other file contains all the even characters. My code gives me no errors and it produces two new files but the two new files contain nothing in them. I am wondering what is wrong with my code(I am sure there is a lot wrong with it). I am still pretty new to programming. </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

void split(char sourceFile[], char destFile1[], char destFile2[]) {
    int chars = 0;
    ifstream sFile;
    sFile.open(sourceFile);
    ofstream file1;
    file1.open(destFile1);
    ofstream file2;
    file2.open(destFile2);

    while (!sFile.eof()) {
        sFile.read(sourceFile + chars, 1);

        cout &lt;&lt; sourceFile[chars];
        if (chars % 2 == 0) {
            file1 &lt;&lt; sourceFile[chars];
        } else {
            file2 &lt;&lt; sourceFile[chars];
        }
        chars++;


    }
}

int main() {
    split("text.txt", "one.txt", "two.txt");
    return 0;
}
</code></pre>
