CArchive::WriteString

void WriteString( LPCTSTR lpsz );
throw( CFileException );

Parameters

lpsz

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

Remarks

Use this member function to write data from a buffer to the file associated with the CArchive object. 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 );

CArchive OverviewClass MembersHierarchy Chart

See Also   CArchive::Write, CArchive::Read, CArchive::ReadString, CFileException