sti*_*tix 1 c++ cout std stringstream
我有以下代码用于格式化打印输出,总是4位数,包含符号:
std::stringstream pitch;
pitch.precision(0);
pitch.width(4);
pitch.fill('0');
pitch << std::showpos << (int)(m_values["Pitch_1"]);
Run Code Online (Sandbox Code Playgroud)
我还想显示符号("+"/" - "),但我希望它在填充之前,如下所示:
+002
Run Code Online (Sandbox Code Playgroud)
但是,我在这里的代码将"+"符号移动到最高位:
00+2
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我如何更改格式以便我拥有前者而不是后者?
使用std::internal操纵器:
pitch << std::internal << std::showpos << 5;
Run Code Online (Sandbox Code Playgroud)