Home > Software engineering >  After the CStdioFile writestring then readstring garbled words
After the CStdioFile writestring then readstring garbled words

Time:09-24

Char pFileName [MAX_PATH];
GetCurrentDirectory (MAX_PATH pFileName);

Cstrings cstrFileFullPath=(cstrings) pFileName + "\ \ SN (Barcode). TXT".
CStdioFile file;
BOOL ret=file. Open (cstrFileFullPath,
CFile: : modeCreate | CFile: : modeNoTruncate | CFile: : modeReadWrite | CFile: : shareDenyWrite);
if (! Ret)
{
AfxMessageBox (" open SN save file failed ");
return;
}

File. SeekToEnd ();
File. WriteString (m_strBarcData + "\ n");

CString str;
File. The ReadString (STR);

Only writestring TXT file data is written to normal, if add to the readstring TXT will appear "tuen tuen tuen tuen tuen tuen tuen tuen mun" of the code

CodePudding user response:

File. WriteString (m_strBarcData + "\ n");//file pointer after the line breaks
CString str;
File. The ReadString (STR);//the again towards the end of the file to read?
BOOL ret=file. ReadString (STR);//see ret!

CodePudding user response:

Written immediately after reading need to manage file location
GetPosition get down file location
The Write Write
Seek to move
Read Read

CodePudding user response:

Fopen, _wfopen
Open a file.

The FILE * fopen (const char * filename, const char * mode).

The FILE * _wfopen (const would * filename, const would * mode).

The Function of Required Header Compatibility
Fopen & lt; Stdio. H> ANSI, Windows 95, Windows NT
_wfopen & lt; Stdio. H> The or & lt; Wchar. H> Windows NT


For additional compatibility information, see compatibility in the the Introduction.

Libraries

LIBC. LIB Single thread static library, retail version
LIBCMT. LIB Multithread static library, retail version
MSVCRT. LIB Import library for MSVCRT DLL, retail version


The c, n, and t mode options are Microsoft extensions for fopen and _fdopen and should not be, informs The where ANSI portability is desired.

The Return Value

Each of these functions provides returns a pointer to the open file. A null pointer value are the an error.

The Parameters

Filename

Filename

Mode

The Type of access permitted

Few

The fopen function opens The file specified by filename. _wfopen is a wide - character version of The fopen; The arguments to _wfopen are wide - character strings. The _wfopen and fopen fitting concepts identically otherwise.

Generic - Text Routine the Mappings

TCHAR. H Routine _UNICODE & amp; _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tfopen fopen fopen _wfopen


The character string mode specifies The type of access requested for The file, as follows:

"R"

Opens for reading. If the file does not exist or always be found, the fopen call fails.

"W"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"A"

Opens for writing at the end of the file (appending) without o the EOF marker before writing new data to the file; Creates the file first if it doesn 't exist.

"R +"

Opens for both reading and writing. (The file must exist.)

"W +"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"A +"

Opens for reading and appending; The appending operation includes the removal of the EOF marker before the new data is written to the file and the EOF marker is restored after writing is complete; Creates the file first if it doesn 't exist.

When a file is the opened with the "a" or "a +" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek, or rewind, but is always version back to the end of the file before any write operation is carried out. Thus, the existing data always be overwritten.

The "a" mode does not remove The EOF marker before appending to The file. After appending has occurred, The ms-dos TYPE The command only shows The data up to The The original EOF marker and not any data appended to The file. The "a +" mode does remove The EOF marker before appending to The file. After appending, The ms-dos TYPE The command shows all The data in The file. The "a +" mode is required for appending to a stream file that is terminated with The CTRL + Z EOF marker.

When the "r +", "w +", or "a +" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). Or, When you switch between reading and writing, there must be an intervening what fflush fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

In addition to the above values, the following characters can be included In the mode to specify the translation mode for newline characters:

T

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related