I'm trying to make a program that would load an entire binary form of a file into the memory and then put it into a newly created file and test if it would behave the same But when I look at the files i see that they aren't the same and that the copy has just a part of the original file
Any Ideas how can I make It work?
Content of an original exe (Part of it there is more)
The Code that I'm useing:
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
int main()
{
bool end = 0;
std::string line;
std::stringstream ss;
std::string Tfile = "Touhou/Touhou06.exe";
std::fstream In_stream(Tfile, std::ios::in, std::ios::binary);
while (std::getline(In_stream, line))
{
ss << line;
}
In_stream.close();
std::string File_content;
ss >> File_content;
ss.clear();
std::fstream Out_stream("TheLong.exe", std::ios::out);
Out_stream << File_content;
Out_stream.close();
}
EDIT: After the changes Code has ended looking like that
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
int main()
{
int length;
bool end = 0;
std::string line;
std::string Tfile = "Touhou/Touhou06.exe";
std::fstream In_stream(Tfile, std::ios::in | std::ios::binary);
In_stream.seekg(0, std::ios::end);
length = In_stream.tellg();
In_stream.seekg(0, std::ios::beg);
std::string buffer(length, '\0');
In_stream.read(&buffer[0], length);
In_stream.close();
std::fstream Out_stream("TheLong.exe", std::ios::out);
Out_stream.write(&buffer[0], length);
Out_stream.close();
}
And it still doesn't work correctly and there is a shift to the content of a copy and I don't know why. At least It seems that there is the full content of the original file