#include <iostream>
#include <iomanip>
#include <locale>
using namespace std;
class BRL : public numpunct<char>
{
protected:
//separador de milhar
virtual char do_thousands_sep() const
{
return ',';
}
//padrão de agrupamento dos milhares, de 3 em 3
virtual std::string do_grouping() const
{
return "\03";
}
};
int main(int argc, char* argv[]){
float _valor = 1022.33;
//instanciando um locale que utilizará a especialização de numpunct
locale br(locale(), new BRL());
//configurar no cout o locale que será utilizado nas formatações
cout.imbue(br);
//setprecistion() é necessário para configurar precisão de apenas duas casas decimais
//fixed é necessário para que o valor não seja impresso como notação científica.
cout << "R$ " << setprecision(2) << fixed << _valor;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGxvY2FsZT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIEJSTCA6IHB1YmxpYyBudW1wdW5jdDxjaGFyPgp7CiAgICBwcm90ZWN0ZWQ6CgogICAgLy9zZXBhcmFkb3IgZGUgbWlsaGFyCiAgICB2aXJ0dWFsIGNoYXIgZG9fdGhvdXNhbmRzX3NlcCgpIGNvbnN0CiAgICB7CiAgICAgICAgcmV0dXJuICcsJzsKICAgIH0KCiAgICAvL3BhZHLDo28gZGUgYWdydXBhbWVudG8gZG9zIG1pbGhhcmVzLCBkZSAzIGVtIDMKICAgIHZpcnR1YWwgc3RkOjpzdHJpbmcgZG9fZ3JvdXBpbmcoKSBjb25zdAogICAgewogICAgICAgIHJldHVybiAiXDAzIjsKICAgIH0KfTsKCmludCBtYWluKGludCBhcmdjLCBjaGFyKiBhcmd2W10pewogICAgZmxvYXQgX3ZhbG9yID0gMTAyMi4zMzsKCiAgICAvL2luc3RhbmNpYW5kbyB1bSBsb2NhbGUgcXVlIHV0aWxpemFyw6EgYSBlc3BlY2lhbGl6YcOnw6NvIGRlIG51bXB1bmN0CiAgICBsb2NhbGUgYnIobG9jYWxlKCksIG5ldyBCUkwoKSk7CgogICAgLy9jb25maWd1cmFyIG5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