点击( 此处 )折叠或打开
- // 方法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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Ant Colony Optimization
Marco Dorigo、Thomas Stützle / A Bradford Book / 2004-6-4 / USD 45.00
The complex social behaviors of ants have been much studied by science, and computer scientists are now finding that these behavior patterns can provide models for solving difficult combinatorial opti......一起来看看 《Ant Colony Optimization》 这本书的介绍吧!