imbue() cout
with a locale
whose numpunct
facet's decimal_point()
member function returns a comma.
Obtaining such a locale
can be done in several ways. You could use a named locale available on your system (std::locale("fr")
, perhaps). Alternatively, you could derive your own numpuct, implement the do_decimal_point()
member in it.
Example of the second approach:
template<typename CharT>
class DecimalSeparator : public std::numpunct<CharT>
{
public:
DecimalSeparator(CharT Separator)
: m_Separator(Separator)
{}
protected:
CharT do_decimal_point()const
{
return m_Separator;
}
private:
CharT m_Separator;
};
Used as:
std::cout.imbue(std::locale(std::cout.getloc(), new DecimalSeparator<char>(',')));