2015-05-21 38 views
1

我已經格式化的打印輸出永遠是4位帶符號下面的代碼包括:使用std :: cout和std :: stringstream時,如何讓填充符號出現在符號末尾?

std::stringstream pitch; 
pitch.precision(0); 

pitch.width(4); 
pitch.fill('0'); 

pitch << std::showpos << (int)(m_values["Pitch_1"]); 

我也想顯示符號(「+」 /「 - 」),但我想它先填充,如下所示:

+002 

不過,我這裏的代碼將「+」號,以最顯著位:

00+2 

如何,如果可能的話,我可以常e格式化,以便我擁有前者,而不是後者?

回答

6

使用std::internal機械手:

pitch << std::internal << std::showpos << 5; 
相關問題