Listing A
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
 
int main()
{
    std::string strDocName = "doc_test.txt";
    int nWordsCount;
    // ... calculate words count
    nWordsCount = 48;
 
 
    // {1} use sprintf - note, NOT type-safe, also
    // problematic if the string you're about to write
    // contains more characters than allocated
    char str1[ 512];
    sprintf( str1, "The %s contains %d words.", strDocName.c_str(), nWordsCount);
 
 
 
 
    // {2} use ecvt; only words for numbers + complicated to use
    int ignored;
    std::string str2 =
        "The " + strDocName +
        " contains " + ecvt( nWordsCount, 2, &ignored, &ignored) + " words";
 
 
    // {3} use _itoa nonportable function
    char strBuffer[ 40];
    std::string str3 =
        "The " + strDocName +
        " contains " + _itoa( nWordsCount, strBuffer, 10) + " words";
  
    return 0;
}