Skip to content

Instantly share code, notes, and snippets.

@MasazI
Created May 25, 2015 04:55
Show Gist options
  • Save MasazI/e3d7ed57ad42f9e427f2 to your computer and use it in GitHub Desktop.
Save MasazI/e3d7ed57ad42f9e427f2 to your computer and use it in GitHub Desktop.
iomanip.cpp
//
// iomanip.cpp
// CplusplusPractice
//
// Created by masai on 2015/05/25.
// Copyright (c) 2015年 masai. All rights reserved.
//
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[]){
// 8進数で表示
cout << oct << 10 << endl;
// 1度設定した値は引き継がれることに注意
cout << 10 << endl;
// 10進数表示に変更
cout << dec << 10 << endl;
// + をつける
cout << showpos << 10 << endl;
// -は通常どおりやればつく
cout << -10 << endl;
// フィールド幅を10桁に設定(上記では、マニピュレータに()がついていない。引数をとらない場合は()をつけない。なぜなら、オーバーロードされたオペレータ<<に渡されるのがマニピュレータのアドレスであるため。)
cout << setw(10) << 100 << endl;
// 16進数
cout << hex << 100 << endl;
// 基数をつける
cout << showbase << 100 << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment