cout

入出力も参照

0で詰めて表示

#include <iostream>
#include <iomanip>
... 
int main(){
  unsigned num = 2;
  cout << setw(4) << setfill('0') << num << endl;              → '0002'

  double fig = 0.15;
  fig+=1e-8;                                                   これがないと,切り上げの関係で '014' になる!!!
  cout << setw(3) << setfill('0') << (int)(100.0*fig) << endl; → '015'
  return 0;
}
最終更新:2010年01月27日 15:51
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。