بإختصار شديد .. لأنه لا يوجد لدي وقت ...
مثل الدالة fixed الموجودة في المكتبة <iostream> ماذا تعمل؟؟
تعمل على تحويل العدد من الشكل التالي وهو scientific number
1.100000e+000
إلى الشكل التالي .. Default Number
1.1
أنظر إلى الـ help الموجود في الـ .net ستري التالي :
Specifies that a floating-point number is displayed in fixed-decimal notation.
ios_base& fixed( ios_base& _Str);
Parameter
_Str
A reference to an object of type
ios_base, or to a type that inherits from
ios_base.
Return Value
A reference to the object from which _Str is derived.
Remarks
fixed is the default display notation for floating-point numbers.
scientific causes floating-point numbers to be displayed using scientific notation.
The manipulator effectively calls
_Str.setf(
ios_base:: fixed,
ios_base:: floatfield), and then returns
_Str.
Example
// ios_fixed.cpp// compile with: /EHsc#include <iostream>int main( ) { using namespace std; float i = 1.1; cout << i << endl; // fixed is the default cout << scientific << i << endl; cout.precision( 1 ); cout << fixed << i << endl;}
Output
1.11.100000e+0001.1
===================================
وايضا الدالة setprecision() في المكتبة <iomanip> ماهو عملها ايضا بالتفصيل؟؟
هذا المثال سيوضح كل شئ ...
#include <iostream>
#include <iomanip>
usingnamespace std;
constdouble d1 = 1.23456789;
constdouble d2 = 12.3456789;
constdouble d3 = 123.456789;
constdouble d4 = 1234.56789;
constdouble d5 = 12345.6789;
constlong l1 = 16;
constlong l2 = 256;
constlong l3 = 1024;
constlong l4 = 4096;
constlong l5 = 65536;
int base = 10;
void DisplayDefault( )
{
cout << endl << "default display" << endl;
cout << "d1 = " << d1 << endl;
cout << "d2 = " << d2 << endl;
cout << "d3 = " << d3 << endl;
cout << "d4 = " << d4 << endl;
cout << "d5 = " << d5 << endl;
}
void DisplayWidth( int n )
{
cout << endl << "fixed width display set to " << n << ".\n";
cout << "d1 = " << setw(n) << d1 << endl;
cout << "d2 = " << setw(n) << d2 << endl;
cout << "d3 = " << setw(n) << d3 << endl;
cout << "d4 = " << setw(n) << d4 << endl;
cout << "d5 = " << setw(n) << d5 << endl;
}
void DisplayLongs( )
{
cout << setbase(10);
cout << endl << "setbase(" << base << ")" << endl;
cout << setbase(base);
cout << "l1 = " << l1 << endl;
cout << "l2 = " << l2 << endl;
cout << "l3 = " << l3 << endl;
cout << "l4 = " << l4 << endl;
cout << "l5 = " << l5 << endl;
}
int main( int argc, char* argv[] )
{
DisplayDefault( );
cout << endl << "setprecision(" << 3 << ")" << setprecision(3);
DisplayDefault( );
cout << endl << "setprecision(" << 12 << ")" << setprecision(12);
DisplayDefault( );
cout << setiosflags(ios_base::scientific);
cout << endl << "setiosflags(" << ios_base::scientific << ")";
DisplayDefault( );
cout << resetiosflags(ios_base::scientific);
cout << endl << "resetiosflags(" << ios_base::scientific << ")";
DisplayDefault( );
cout << endl << "setfill('" << 'S' << "')" << setfill('S');
DisplayWidth(15);
DisplayDefault( );
cout << endl << "setfill('" << ' ' << "')" << setfill(' ');
DisplayWidth(15);
DisplayDefault( );
cout << endl << "setprecision(" << 8 << ")" << setprecision(8);
DisplayWidth(10);
DisplayDefault( );
base = 16;
DisplayLongs( );
base = 8;
DisplayLongs( );
base = 10;
DisplayLongs( );
return 0;
}