点击( 此处 )折叠或打开
- // 方法1
- cout < < hex < < i < < endl ; //输出十六进制数
- cout < < oct < < i < < endl ; //输出八进制数
- cout < < dec < < i < < endl ; //输出十进制数
- //方法2
- // 输出16进制, setbase(int)可以设置8等。
- cout < < setbase ( 16 ) < < i < < endl ;
- // 方法3
- setiosflags ( ios : : showbase ) ;
- cout < < hex < < i < < endl ;
- cout . setf ( ios : : showbase ) ;
- cout . setf ( ios_base : : hex , ios_base : : basefield )
点击( 此处 )折叠或打开
- cout 输出 16 , 8 , 2进制
- # include < iostream >
- # include < iomanip >
- # include < bitset >
- using std : : bitset ;
- using std : : hex ;
- using std : : oct ;
- using std : : cout ;
- using std : : cin ;
- using std : : endl ;
- int main ( )
- {
- int a = 10 ;
- cout < < "Dec:" < < a < < endl ;
- cout < < hex < < "Hex:" < < a < < endl ;
- cout < < oct < < "Oct:" < < a < < endl ;
- cout < < bitset < 32 > ( a ) < < endl ;
- getchar ( ) ;
- return 0 ;
点击( 此处 )折叠或打开
- C + + 操作符
- 注:下面的scientific 和 fixed不能同时使用
- double a = 123 . 456789012345 ; 对a赋初值
- ( 1 ) cout < < a ; 输出: 123 . 456
- ( 2 ) cout < < setprecision ( 9 ) < < a ; 输出: 123 . 456789
- ( 3 ) cout < < setprecision ( 6 ) ; 恢复默认格式 ( 精度为6 )
- ( 4 ) cout < < setiosflags ( ios∷fixed ) ; 输出: 123 . 456789
- ( 5 ) cout < < setiosflags ( ios∷fixed ) < < setprecision ( 8 ) < < a ; 输出: 123 . 45678901
- ( 6 ) cout < < setiosflags ( ios∷scientific ) < < a ; 输出: 1 . 234568e + 02
- ( 7 ) cout < < setiosflags ( ios∷scientific ) < < setprecision ( 4 ) < < a ; 输出: 1 . 2346e02
- 下面是整数输出的例子:
- int b = 123456 ; 对b赋初值
- ( 1 ) cout < < b ; 输出: 123456
- ( 2 ) cout < < hex < < b ; 输出: 1e240
- ( 3 ) cout < < setiosflags ( ios∷uppercase ) < < b ; 输出: 1E240
- ( 4 ) cout < < setw ( 10 ) < < b < < ′ , ′ < < b ; 输出: 123456,123456
- ( 5 ) cout < < setfill ( ′ * ′ ) < < setw ( 10 ) < < b ; 输出: * * * * 123456
- ( 6 ) cout < < setiosflags ( ios∷showpos ) < < b ; 输出: + 123456
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 2. Python中的基本输入、输出、格式化输出
- Go中格式化输出
- golang printf 格式化输出
- Golang 中的格式化输入输出
- Java读取Excel并解析文本(并格式化输出)
- 【译】Java8官方教程:格式化输出数值类型
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Think Python
Allen B. Downey / O'Reilly Media / 2012-8-23 / GBP 29.99
Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms ......一起来看看 《Think Python》 这本书的介绍吧!
JS 压缩/解压工具
在线压缩/解压 JS 代码
XML、JSON 在线转换
在线XML、JSON转换工具