Hey everybody! Im doing a project for my fundamentals of programming class and I'm almost done but Im having trouble inserting a dollar sign ($) next to the values of
totalRevenue, revenue2Theater, and revenue2Distrib. I tried multiple ways to insert the dollar sign ($) but the whole formatting gets screwed up in the output. Thanks.
If the standard library supports the US locale (ie. any reasonable library other than the GNU library on non-linux platforms), std::put_money can be used. http://en.cppreference.com/w/cpp/io/manip/put_money
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <iomanip>
int main()
{
constdouble amount_in_dollars = 123.456789 ;
constunsignedlonglong cents = amount_in_dollars * 100.0 + 0.5 ;
// imbue the locale for US. note: supported locales and locale names other than
// standard C locale names ("C" and "POSIX") are implementation defined
std::cout.imbue( std::locale("en_US.utf8") );
std::cout << std::showbase
<< std::setw(12) << std::put_money(cents) << '\n'
<< std::setw(12) << std::put_money( cents, true ) << '\n' ;
}