Home > Software engineering >  For binary data file is written to use which function
For binary data file is written to use which function

Time:05-27

Want to realize such a function:
Write data at the location on the file, if the original position data, replace, insert can,
Sequential writes data in the file
Write data in the file, don't remove the original file content, but write data directly in the file


Excuse me, is there a function as a function of these?

Ofstream ofs (" test. TXT ", the ios: : binary);//such as this, can only write data sequence, will remove the original file content
Ofs. Write ((char *) & amp; A, sizeof (int));
Ofs. Write ((char *) & amp; A, sizeof (int));
Ofs. Close ();

CodePudding user response:

CFile: : Seek

Virtual LONG Seek (LONG lOff, UINT nFrom);
Throw (CFileException);

The return value:
If request the position of the legal, Seek returns the new byte offset from the file beginning, otherwise the value undefined and generate CFileException abnormalities,

Parameters: lOff pointer bytes,
NFrom pointer mode, can be one of the following values: CFile: : begin from file, move the pointer backward lOff bytes,
CFile: : current starting from the current position, move the pointer backward lOff bytes,
CFile: : end from the beginning of the end-of-file, move the pointer forward lOff bytes, attention must be moved to the existing file, thus lOff should be negative, if positive, is beyond the end-of-file,

CodePudding user response:

Before writing with the sentence:
Ofs. Seekp (offset, the ios: : beg);//position to the first byte offset
  • Related