String manipulation, when converted show 0 in the beginning of the string

c++, string

Solution

Use io manipulators `setfill` and `setw`:

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>

int main()
{
    std::ostringstream s;

    s << std::setfill('0') << std::setw(6) << 154;

    std::cout << s.str() << "\n";

    return 0;
}

Problem

I want to know how can I make the `string` I converted from `DWORD` to `onstringstream` and then to `AnsiString`. But that doesn't really matter, the conversion could be from `int` to `string`, I just want to know how I can make every string converted to ALWAYS show `6` digits, like if my number is `57`, in the `string` it will be `000057`. Thanks!

Original source