我想知道如何使string
我从转换DWORD
为onstringstream
然后转换为AnsiString
。
但这并不重要,转换可能是 from int
to string
,我只是想知道如何让每个字符串转换为 ALWAYS show 6
digits,比如如果我的号码是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;
}