Inserting and removing commas from integers in c++ -
There is too much no Noob, so I think I do not know anything in any answer.
I 'am writing a little app, and it's working well, but readability is a nightmare with my numbers.
Essentially, all I want to do is add a comma to the number displayed on the screen to make the screen is easy to read. Is there a quick and easy way to do this?
I am using stringstream to catch my numbers (I'm not sure that at this point it has been suggested, it was only suggested in the tutorial I have worked) Such as (unchanged bits crop):
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Sstream & gt; using namespace std; Int item; String string check; ... cout & lt; & Lt; "How many items you have to enter:"; Gateline (pin, string check); Stringstream (string check) & gt; & Gt; item; ... cout & lt; & Lt; "\ NYou have" & lt; & Lt; Item & lt; & Lt; "Items. \ N"; When that number is typed as something larger, then there is a lot of headache in reading it in everything else.
Is there a quick and easy way to print "13653456" unlike "13653456" as it would be right now (assuming it was definitely input)?
Note: If it matters, then I'm making it as a console application in Microsoft Visual C ++ 2008 Express Edition.
Try the function and overload the function. There on one I hacked anything that fixes your problem:
#include & lt; Locale & gt; # Include & lt; Iostream & gt; Class my_numpunct: public std :: numpunct & lt; Char & gt; {Std :: string do_grouping () const {return "\ 3"; }}; Int main () {std :: locale nl (std :: locale (), new my_numpunct); Std :: cout.imbue (nl); Std :: cout & lt; & Lt; 1000000 & lt; & Lt; "\ N"; // do not use thousands of separators' std :: cout.imbue (std :: locale ()); Std :: cout & lt; & Lt; 1000000 & lt; & Lt; "\ N"; // uses thousands separators}
Comments
Post a Comment