CArchive::WriteString
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

CArchive::WriteString

Use this member function to write data from a buffer to the file associated with the CArchive object.

void WriteString(
   LPCTSTR lpsz 
);

Parameters

lpsz
Specifies a pointer to a buffer containing a null-terminated text string.

Remarks

The terminating null character ('\0') is not written to the file; nor is a newline automatically written.

WriteString throws an exception in response to several conditions, including the disk-full condition.

Write is also available, but rather than terminating on a null character, it writes the requested number of bytes to the file.

Example

CFile myFile("myfile", CFile::modeCreate | CFile::modeReadWrite);
CString str1="String1", str2="String2", str;

// Create a storing archive.
CArchive arStore(&myFile, CArchive::store);

// Write str1 and str2 to the archive
arStore.WriteString( str1 );
arStore.WriteString( "\n" );
arStore.WriteString( str2 );
arStore.WriteString( "\n" );

// Close the storing archive
arStore.Close();

// Create a loading archive.
myFile.SeekToBegin();
CArchive arLoad(&myFile, CArchive::load);

// Verify the two strings are in the archive.
arLoad.ReadString( str );
ASSERT( str == str1 );
arLoad.ReadString( str );
ASSERT( str == str2 );

See Also

CArchive Overview | Class Members | Hierarchy Chart

Show:
© 2016 Microsoft