Well I guess I decided to give up on my XOR thing... anyway, I am now writing a program that edits .swf files, just changing the first three characters. I haven't gotten to changing those characters just yet, as I'm having a problem just copying them. They are just binary files, and I should be able to copy them just fine, but when I compare the input and output with UltraCompare, the two have a lot of differences. All that I'm trying to do at the current moment is copy them. Does anyone know why the output the is so different from the input? Here's my code:
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using std::string;
string fileName;
ifstream* openFile()
{
for(;;)
{
cout << "Enter the name of a file" << endl;
getline(cin, fileName);
ifstream* pFileStream = new ifstream((fileName).c_str(), ios::binary);
if (pFileStream->good())
{
return pFileStream;
}
cerr << "Couldn't find " << fileName << endl;
}
}
int main()
{
ifstream* pFileStream = openFile();
int x = fileName.length();
int xx = x - 4;
fileName.insert(xx, "S");
cout << fileName << endl;
system("pause");
ofstream out((fileName).c_str());
char buffer[80];
while (!pFileStream->eof() && pFileStream->good())
{
pFileStream->read(buffer, 80);
int noBytes = pFileStream->gcount();
for(int i = 0; i < noBytes; i++)
{
out << buffer[i];
}
}
system("pause");
}
Before someone makes a comment about this line of code :
Code:
fileName.insert(xx, "S");
and the preceding two, let me just say that I wanted the original different from the output, it may not be the right way, but it's how I'm doing it. Anyway, any help would be appreciated.