Fout in kopieer code

Status
Niet open voor verdere reacties.

manhaeve5

Gebruiker
Lid geworden
9 jan 2007
Berichten
276
Dit is mijn code om bestanden te kopieren
Code:
bool kopieer(const char *filename,const char *filename2)
{
     char *data;
     int length;
     ifstream input(filename,ifstream::binary);
     if(!input.is_open())
                      return false;
     input.seekg(0,ios::end);
     length=input.tellg();
     input.seekg(0,ios::beg);
     data=new char(length);
     cout<<"length="<<length<<endl;
     input.read(data,length);
     input.close();
     ofstream output(filename2,ofstream::binary);
     output.write(data,length);
     output.close();
     delete data;
     return true;
}
Het werkt goed bij textbestanden maar het werjkt niet bij andere extensies. Hoe komt dit?
 
Opelost. Het probleem was dat ik volledige bestanden het geheugen inlaade en dat was te groot.
 
Uit de WIN32 API documentatie:



The CopyFile function copies an existing file to a new file.

BOOL CopyFile(

LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);
Parameters

lpExistingFileName

Points to a null-terminated string that specifies the name of an existing file.

lpNewFileName

Points to a null-terminated string that specifies the name of the new file.

bFailIfExists

Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Security attributes for the existing file are not copied to the new file.
File attributes (FILE_ATTRIBUTE_*) for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For further information on file attributes, see CreateFile.
 
Code:
system("COPY <hier_je_args>");
;)

Maar kan je even je oplossing posten dan? Ben wel geïnteresseerd...

--Johan
 
Kijk dan hier, dat is mijn library en de functie zit daarin met nog een paar andere
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan