我想知道如何使string我从转换DWORD为onstringstream然后转换为AnsiString。
但这并不重要,转换可能是 from intto string,我只是想知道如何让每个字符串转换为 ALWAYS show 6digits,比如如果我的号码是57,string那么它将是000057。
谢谢!
使用io 操纵器 setfill和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;
}
那么,关于格式化输出的问题?你可以使用iostream::width和`iostream::fill':
// field width
#include <iostream>
using namespace std;
int main () {
  cout << 100 << endl;
  cout.width(6);
  cout.fill('0');
  cout << 100 << endl;
  return 0;
}