Add leading zero's to string, without (s)printf

后端 未结 7 1833
孤独总比滥情好
孤独总比滥情好 2020-12-08 19:49

I want to add a variable of leading zero\'s to a string. I couldn\'t find anything on Google, without someone mentioning (s)printf, but I want to do this without (s)printf.<

7条回答
  •  孤街浪徒
    2020-12-08 20:11

    The C++ way of doing it is with setw, ios_base::width and setfill

    #include 
    #include 
    
    using namespace std;
    
    int main()
    {
        const int a = 12;
        const int b = 6;
    
        cout << setw(width) << row * col;
        cout << endl;
    
        return 0;
    }
    

提交回复
热议问题