is there a manipulator in C++ that do that ?

if not how can i cout my numbers formatted that way .

if the number is larger than 999.99 i want to put a comma after the first 3 digits and after the 6 digits ..etc

x = 99456
Example : cout << X

shows in the screen : 99,456 instead of 99456 .

Read this thread

thanks a lot. i thought there is a manipulator the can do the job directly.

is this the easiest way "fixed a couple of bugs (brute force version). "

it seems too long for adding a comma for the thousand / million ranges

That is only one way to do it. A more generic way would be to first convert the int to string, then copy the digits in reverse order (from right to left) into another string adding the commas. Finally you will have to reverse the result string because it will be backwards. std::reverse() will do that.

A more generic way would be to first convert the int to string, then copy the digits in reverse order (from right to left) into another string adding the commas. Finally you will have to reverse the result string because it will be backwards. std::reverse() will do that.

Unless you copy into the string starting at the end of the destination string.

great , thanks all for the help .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.