让一个数字显示指定位数

  1. #include <iostream>  
  2. #include <iomanip>//一定要包含这个c++头文件,非常重要  
  3.   
  4. using namespace std;  
  5.   
  6. int main()  
  7. {  
  8.     int test[4] = { 1, 12, 123, 1234 };  
  9.     for (int i = 0; i < 4; ++i)  
  10.     {  
  11.         cout << setw(4) << setfill('0') << test[i] << " ";  
  12.     }  
  13.     cout << endl << endl;  
  14.     return 0;  
原文地址:https://www.cnblogs.com/zhubaohua-bupt/p/7182820.html