Output File smaller than Input file?


What im doing is loading a file in to an array, and simply writing that array to another file. When I do this, the size is different, and the file no longer works correctly, or shows the proper text (if its a .txt). I do no want to simply copy the file, but I want to manipulate the ASCII numbers in the array as well, but I cant seem to get it to output right.

Here is the experts from my code that I think are prudent:

1
2
3
4
5
6
7
8
9
10
ifstream file;																
file.open (filename, ios::binary|ios::ate);
if (file.is_open())           
	{
	size = file.tellg();
	memblock = new char [size];
	file.seekg (0, ios::beg);
	file.read (memblock, size);
	file.close();
	}

....

1
2
3
4
5
ofstream fileout (outname);							
if (fileout.is_open()){
	for (int n=0; n<size; n++)
    fileout << memblock[n];
	cout << "\n" << "Encrypted data written to " << outname << "\n";


It works with very small .txt files (a couple 100 bytes), but after some point, it screws up for some reason :S
Last edited on
Don't forget to open with ios::binary.
Topic archived. No new replies allowed.