Format Problem

  • Thread starter Thread starter Manfred Huber
  • Start date Start date
M

Manfred Huber

Hello,

I'm using VC++ 7.0 .NET. It seems that the "%d" and "%f" format parameters
are not supported anymore. Following code does not work:

StatusLabel->Text = String::Format ("Reading %d bytes (%0.1f Kb/s)",
__box(lBytes), __box (dTransferRate));

If I used this code with VC++ 6.0 and MFC it worked without any problems? Do
you have an idea how to solve this?
 
Manfred said:
Hello,

I'm using VC++ 7.0 .NET. It seems that the "%d" and "%f" format
parameters are not supported anymore. Following code does not work:

StatusLabel->Text = String::Format ("Reading %d bytes (%0.1f Kb/s)",
__box(lBytes), __box (dTransferRate));

If I used this code with VC++ 6.0 and MFC it worked without any
problems? Do you have an idea how to solve this?

You can't possibly have used this code with VC6 or MFC, since what you've
posted here is .NET code.

I think you've got the C standard library routines {v}{s|f}printf confused
with System::Format.

-cd
 
You can't possibly have used this code with VC6 or MFC, since what you've
posted here is .NET code.

In VC6 with MFC i used
CString str;
str.Format ("Reading %d bytes (%0.1f Kb/s)", lBytes,dTransferRate);

What I wanted to say is that the .NET does not support the %d and %o.1f
parameters anymore.
 
Manfred said:
In VC6 with MFC i used
CString str;
str.Format ("Reading %d bytes (%0.1f Kb/s)", lBytes,dTransferRate);

What I wanted to say is that the .NET does not support the %d and
%o.1f parameters anymore.

String::Format is completely different from CString.Format (which uses
vsnprintf internally).

See

http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconCompositeFormatting.asp
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconFormattingOverview.asp
http://msdn.microsoft.com/library/d...us/cpguide/html/cpconnumericformatstrings.asp

For information on how to use System::String::Format.

You original example of
StatusLabel->Text = String::Format ("Reading %d bytes (%0.1f Kb/s)",
__box(lBytes), __box (dTransferRate));

should be written:

StatusLabel->Text = String::Format("Reading {0} bytes ({1:0.0}Kb/s)",
__box(lBytes), __box (dTransferRate));


HTH

-cd
 
Back
Top