Article ID: 123161
Article Last Modified on 7/5/2005
--- Output Starts ---
+ 1234 // Correct, positive integer with space between
+ and 1234.
+ 1234 // Correct, positive long integer.
+ 1234.000 // Correct, positive float.
+ 1234.000 // Correct, positive double.
-1234 // Incorrect, negative integer with no space
between - and 1234.
-1234 // Incorrect, negative long integer.
- 1.23e+003 // Correct, negative float in scientific notation.
- 1.23e+003 // Correct, negative double.
--- Output Ends ---
/* Compile options needed: none
*/
#include <IOSTREAM.H>
#include <IOMANIP.H>
#pragma warning( disable : 4270 )
#define WIDTH 20
void main( void )
{
int i = 1234;
cout.flags( ios::showpos | ios::internal );
cout << setw(WIDTH) << (int) i << endl;
cout << setw(WIDTH) << (long) i << endl;
cout.precision(3);
cout.flags( ios::showpos | ios::internal | ios::fixed );
cout << setw(WIDTH) << (float) i << endl;
cout << setw(WIDTH) << (double) i << endl;
cout << setw(WIDTH) << (int)-i << endl; // Problem
cout << setw(WIDTH) << (long)-i << endl; // Problem
// The following two lines show how to work around the problem.
// cout << setprecision(0) << setw(WIDTH) << (float)-i << endl;
// cout << setprecision(0) << setw(WIDTH) << (float)-i << endl;
cout.precision(3);
cout.flags( ios::showpos | ios::internal | ios::scientific );
cout << setw(WIDTH) << (float)-i << endl;
cout << setw(WIDTH) << (double)-i << endl;
}
Additional query words: kbVC400bug buglist1.50 buglist1.00 buglist2.00
Keywords: kbbug kbcodegen KB123161