运行 ❯
获取您
自己
的网站
×
更改方向
更改主题,深色/浅色
前往 Spaces
#include <iostream> #include <iomanip> using namespace std; int main() { // Booleans cout << "Booleans\n"; cout << false << "\n"; cout.setf(ios::boolalpha); cout << false << "\n"; // Hexadecimal and octal numbers cout << "\nHexadecimal and octal numbers\n"; int myInt = 14; cout << myInt << "\n"; cout.setf(ios::hex, ios::basefield); cout << myInt << "\n"; cout.setf(ios::oct, ios::basefield); cout << myInt << "\n"; cout.setf(ios::showbase); cout.setf(ios::uppercase); cout.setf(ios::hex, ios::basefield); cout << myInt << "\n"; cout.setf(ios::oct, ios::basefield); cout << myInt << "\n"; cout.setf(ios::dec, ios::basefield); // Floating point numbers cout << "\nFloating point numbers\n"; float myFloat = 19.99; cout << myFloat << "\n"; cout.setf(ios::fixed, ios::floatfield); cout << myFloat << "\n"; cout.setf(ios::scientific, ios::floatfield); cout << myFloat << "\n"; cout.unsetf(ios::floatfield); cout.setf(ios::showpos); cout.setf(ios::showpoint); cout << 12345.0 << "\n"; // Alignment cout << "\nAlignment\n"; cout.setf(ios::left, ios::adjustfield); cout << setw(10) << "Left" << "\n"; cout.setf(ios::right, ios::adjustfield); cout << setw(10) << "Right" << "\n"; cout.setf(ios::internal, ios::adjustfield); cout << setw(10) << 12345.0 << " (Internal)\n"; return 0; }
布尔值
0
false
十六进制和八进制数
14
e
16
0XE
016
浮点数
19.99
19.990000
1.999000E+01
+12345.0
对齐方式
左
右
+ 12345.0 (内部)