C++/Console/cout setf — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Версия 14:21, 25 мая 2010
Содержание
- 1 cout: how to display float number, ios::showpoint, ios::showpos
- 2 cout.setf(ios::hex)
- 3 cout.setf(ios::showbase)
- 4 cout.setf(ios::showpos | ios::showpoint) and cout.setf(ios::showpoint, ios::showpos | ios::showpoint)
- 5 cout.setf(ios::uppercase | ios::scientific)
- 6 Set cout: hex, basefield, setf(ios::hex, ios::basefield)
- 7 Set cout: setf(ios::showpoint | ios::showpos, ios::showpoint)
- 8 You can OR together two or more flags: ios::uppercase | ios::scientific
cout: how to display float number, ios::showpoint, ios::showpos
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::showpoint);
cout.setf(ios::showpos);
cout << 100.0;
return 0;
}
cout.setf(ios::hex)
#include <iostream>
using namespace std;
int main(void) {
cout.setf(ios::hex);
cout << 100;
cout.setf(ios::showbase);
cout << 100;
}
cout.setf(ios::showbase)
#include <iostream>
using namespace std;
int main(void) {
cout.setf(ios::hex);
cout << 100;
cout.setf(ios::showbase);
cout << 100;
}
cout.setf(ios::showpos | ios::showpoint) and cout.setf(ios::showpoint, ios::showpos | ios::showpoint)
#include <iostream>
using namespace std;
int main(void){
cout.setf(ios::showpos | ios::showpoint);
cout << 100 << endl;
cout.setf(ios::showpoint, ios::showpos | ios::showpoint);
cout << 100;
}
cout.setf(ios::uppercase | ios::scientific)
#include <iostream>
using namespace std;
int main(void) {
cout.setf(ios::uppercase | ios::scientific);
cout << 100.12;
cout.unsetf(ios::uppercase);
cout << endl << 100.12;
}
Set cout: hex, basefield, setf(ios::hex, ios::basefield)
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 100;
return 0;
}
Set cout: setf(ios::showpoint | ios::showpos, ios::showpoint)
#include <iostream>
using namespace std;
int main( )
{
cout.setf(ios::showpoint | ios::showpos, ios::showpoint);
cout << 100.0;
return 0;
}
You can OR together two or more flags: ios::uppercase | ios::scientific
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::uppercase | ios::scientific);
cout << 1001.12;
cout.unsetf(ios::uppercase); // clear uppercase
cout << " \n" << 1100.12;
return 0;
}