C++/Console/cout scientific
Содержание
cout: change formats
#include <iostream>
using namespace std;
int main()
{
// change formats
cout.unsetf(ios::dec);
cout.setf(ios::hex | ios::scientific);
cout << 123.23 << " hello " << 100 << "\n";
cout.setf(ios::showpos);
cout << 10 << " " << -10 << "\n";
cout. setf(ios::showpoint | ios::fixed);
cout << 100.0;
return 0;
}
cout: number base, justification, and format flags
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 300;
return 0;
}
Displays the value 100 with the showpos and showpoint flags turned on
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::showpoint);
cout.setf(ios::showpos);
cout << 100.0;
return 0;
}
Sets both the uppercase and scientific flags and clears the uppercase flag
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::uppercase | ios::scientific);
cout << 1010.112;
cout.unsetf(ios::uppercase); // clear uppercase
cout << endl << 1100.112;
return 0;
}