$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Daniel James (gmane.junk001_at_[hidden])
Date: 2008-01-30 07:29:50
The documentation states that the same format string used with printf 
and boost::format should result in the same output in "almost all 
cases".
My colleagues and I have found, though, that when a %d descriptor is 
used to print a char variable the result is as though a %c descriptor 
had been used -- printf and boost::format don't produce the same 
result.
That is:
  int ii(42);
  char cc(42);
  
  printf( "Using printf: ii=%d, cc=%d\n", ii, cc );
  cout << boost::format( "Using boost::format: ii=%d, cc=%d" ) % 
      ii % cc << endl;
      
Produces:
Using printf: ii=42, cc=42
Using boost::format: ii=42, cc=*
So, it seems that boost::format deduces the format to be used for 
outputting cc from its type and ignores the format explicitly requested 
in the format.
Is this working as intended? If so the documentation seems to me to be 
misleading.
I also note that:
  cout << boost::format( "As chars: ii=%c, cc=%c" ) % ii % cc << endl;
Produces:
As chars: ii=4, cc=*
That is: the %c descriptor causes the value of ii (42) to be truncated 
to a single char. Also something of a surprise.
My tests were carried out using boost 1.34.1 and Visual Studio 2005 on 
Windows.
Cheers,
 Daniel.