C++入門經典-例2.7-輸出整數,控制打印格式
阿新 • • 發佈:2017-09-11
設置 hid 整數 set gif 打印格式 str png name
1:代碼如下:
// 2.8.cpp : 定義控制臺應用程序的入口點。 // #include "stdafx.h" #include <iostream> #include <iomanip> using namespace std; void main() { int b=123456; //對b賦初值 cout << b << endl; //輸出: 123456 cout << hex << b << endl; //View Code輸出: 1e240//hex表示16進制 cout << setiosflags(ios::uppercase) << b << endl; //輸出: 1E240 //ios::uppercase大寫顯示, cout << setw(10) << b <<‘,‘<< b << endl; //輸出: 123456,123456//設置寬度為10,且靠右排列 cout << setfill(‘*‘) << setw(10) << b << endl; //輸出: **** 123456//設置寬度為10,靠右排列,且空格補充* cout << setiosflags(ios::showpos) << b << endl; //輸出: +123456//顯示正負號 }
運行結果:
C++入門經典-例2.7-輸出整數,控制打印格式