1. 程式人生 > >C++入門經典-例2.7-輸出整數,控制打印格式

C++入門經典-例2.7-輸出整數,控制打印格式

設置 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;                     //
輸出: 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//顯示正負號 }
View Code

運行結果:

技術分享

C++入門經典-例2.7-輸出整數,控制打印格式