Wczytywanie i zapis każdego typu plików

0

Chciałem napisać program, który dla podanej ścieżki wczyta dowolny plik graficzny, tekstowy, jakieś archiwum czy plik exe
i będzie mógł go zapisać w postaci nie naruszonej do innej lokalizacji.
Użyłem do tego biblioteki fstream - może polecicie jakąś inną?
Program się wykonuje ale gdy zapisuje wczytany plik jest on uszkodzony.
Napisałem taką klasę.
Mógłby ktoś przejrzeć kod bo chyba mi coś umyka.

#include <fstream>
#include <iostream>
#include <cstring>

class CFile
{
    public:
    bool LoadFile(std::string path);
    void SaveFile(std::string path);
    ~CFile();
    char * buffer;
    int length;
};
bool CFile::LoadFile(std::string path)
{
    std::fstream file;
    file.open( path, std::ios::binary | std::ios::in );
    if ( file.good() )
    {
       file.seekg( 0, std::ios::end );
       length = file.tellg();
       file.seekg( 0, std::ios::beg );

       buffer = new char [length];
       file.read( buffer, length );
       file.close();
       return 1;
    }
    return 0;
}
void CFile::SaveFile(std::string path)
{
    std::fstream file( path, std::ios::out | std::ios::binary);
    file.write( & buffer[ 0 ], strlen(buffer) );
    file.flush();
    file.close();
}
CFile::~CFile()
{
    delete [] buffer;
}
0
file.write(buffer,length);
0

Dzięki działa zacnie :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1