CString::FormatV

void FormatV( LPCTSTR lpszFormat**, va_list** argList );

Parameters

lpszFormat

A format-control string.

argList

A list of arguments to be passed.

Remarks

Call this member function to write a formatted string and a variable list of arguments to a CString object in the same way that vsprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. The string and arguments are converted and output according to the corresponding format specification in lpszFormat.

The call will fail if the string object itself is offered as a parameter to FormatV. For example, the following code:

CString str = "Some Data";
str.FormatV("%s%d", str, 123);   // Attention: str is also used in the parameter list.

will cause unpredictable results.

For more information, see in the Run-Time Library Reference.

Example

//Using CString::FormatV(), you can write functions like the following:

void WriteLogEntry(CStdioFile& refFile, LPCTSTR pstrFormat, ...)
{
   CTime timeWrite;
   timeWrite = CTime::GetCurrentTime();

   // write the time out
   CString str = timeWrite.Format("%d %b %y %H:%M:%S - ");
   refFile.Write(str, str.GetLength());

   // format and write the data we were given
   va_list args;
   va_start(args, pstrFormat);
   str.FormatV(pstrFormat, args);
   refFile.Write(str, str.GetLength());

   // put a newline
   refFile.Write("\n", 1);
   return;
}

You can call the above function with any number of parameters, for example:

   WriteLogEntry(fileLog, "Program started");
   WriteLogEntry(fileLog, "Processed %d bytes", 91341);
   WriteLogEntry(fileLog, "%d error(s) found in %d line(s)", 10, 1351);
   WriteLogEntry(fileLog, "Program completed");

which would add output  to your fileLog file similar to the following:

   17 Apr 97 12:34:53 - Program started
   17 Apr 97 12:34:59 - Processed 91341 bytes
   17 Apr 97 12:35:22 - 10 error(s) found in 1351 line(s)
   17 Apr 97 12:35:23 - Program completed

CString OverviewClass MembersHierarchy Chart

See Also   CString::Format,