#include <iostream> #include <iomanip> int frameCount = 0; while(1){ stringstream buf; buf <<setfill('0') << setw(4)<< frameCount; string num = buf.str(); frameCount++; } for(int i=0; i < 15; i++) { cout << setfill('0') << setw(4) << i << endl; }
参考 http://stackoverflow.com/questions/2999016/print-numbers-sequentially-using-printf-with-filling-zeroes