How to not print the positive sign in a non-US locale

Hi,

I am using a non-US locale that defines the positive sign as "+" but I don't want it displayed... However I am having trouble and the solution I found seems way too complicated to be considered the best. Here is my code that shows the original problem (I am running Visual Studio 2015 update 3 in Windows):

1
2
3
4
5
        locale loc ("sp-CR");
	cout.imbue(loc);
	cout << showbase;
	auto& f = use_facet<money_put<char>>(loc);
	f.put(cout, false, cout, ' ', 12345678.90);


And here is my "solution":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	class costaRicaNumPunct : public std::moneypunct_byname<char>
	{
	public:
		costaRicaNumPunct(const std::string& name)
			: std::moneypunct_byname<char>("sp-CR")
		{}
	protected:
		virtual std::string do_positive_sign() const override {
			return "";
		}
	};

   void outputMoney()
   {
	locale crLoc(locale("en-US"), new costaRicaNumPunct{ "" });
	cout.imbue(crLoc);
	cout << showbase;
	auto& mp = use_facet<money_put<char>>(crLoc);
	mp.put(cout, false, cout, ' ', 12399777.867);
   }


So, is there an easier solution?

Thanks

Juan
Topic archived. No new replies allowed.