2017-11-18 6 views
0

10進数を印刷しようとしています。 "##### + 3.01" ケース:小数点はありません(この場合は3.01とします)。私はその記号+/-を先にy noで印刷しなければなりません。 #、いくつかの合計の幅を修正します。 (この場合、x = 10とします)。C++でsetfill()を使用して特定の形式の10進数を出力します。

私はこのような何かを試してみました:

double no = 3.01; 
    cout << setfill('#') << setw(10) ; 
    cout << setiosflags(ios::showpos); 
    cout << fixed << setprecision(2) << no << endl; 

しかし、私はfollowinfg出力取得しています:

+#####3.01 

予想される出力:

#####+3.01 
+2

可能な複製(https://stackoverflow.com/questions/ 46729847/stdostringstream-puts-sign-in-wrong-location) – Barmar

答えて

0

あなたのコードは私に正しい結果を与えました。私はLinuxマシンを使用しています。

念のために、それは、このコードを試し、OSに依存する問題である:[?のstd :: ostringstreamは間違った場所に看板を置く]の

#include <iostream> 
#include <iomanip> 

using namespace std; 

int main() 
{ 
    double no = 3.01; 
    cout << setfill('#') << std::right<< setw(10) ; 
    cout << setiosflags(ios::showpos); 
    cout << fixed << setprecision(2) << no << endl; 
} 
+0

それは働いた。ありがとう。 –

関連する問題