Monday 15 July 2013

c++ - File read write using MFC CFile -


I'm thinking why not write down the code below in the correct file? If I change buffer size to something bigger then this code works fine.

For the code given below, if I try to read files less than 500 bytes, then it works fine, but for a large file, I just have to increase the buffer in the read loop. What is missing?

const iBuffSiz = 500; Four cheebber [iBuffSiz]; Memmets (Chubber, 0, chBuffer); Cfile file; O cfile file; If (file.Open (XML_FILE_NAME, cfile :: mode read | cfile :: typebayer == incorrect) {return; } If (fileO.Open (XML_FILE_NAME_O, CFile :: modeCreate | CFile :: modeWrite | CFile :: typeBinary) == incorrect) {return; } While (read the file (chBuffer, iBuffSiz)> 0) {try {UINT iCount = strlen (chBuffer); FileO.Write (chBuffer, iCount); } Catch (cipher expansion * XP) {TCHAR Says Seas [255]; Exp- & gt; GetErrorMessage (szCause, 255); }} // File file handle and close the socket after sending the complete file. Stop it (); FileO.Close ();

cfile :: read buffer does not end up faucet, Buffer can be larger than the strlen buffer, it runs in buffer overflow, there is a way to bring it around, but Stellen still does not work with binary files If the buffer is too small at this time then it is better to use the value returned by the UINT iCount; CFile :: read

  While reading (iCount = File) (chBuffer, iBuffSiz) gt; {} {try fileO.Write (chBuffer, iCount);} Catch (cipher expansion * XP) {TCHAR Says Seas [255]; Exp- & gt; GetErrorMessage (szCause, 255);}}  

No comments:

Post a Comment