1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/* Copyright (C) 2007 The glibmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glibmm.h>
#include <iomanip>
#include <iostream>
#include <locale>
namespace
{
void
show_examples()
{
using Glib::ustring;
const double a = 3456.78;
const double b = 7890.12;
const int i = int(a / (a + b) * 40.0);
std::cout << ustring::compose("%1 is lower than %2.", a, b) << std::endl
<< ustring::compose("%2 is greater than %1.", a, b) << std::endl
// ustring::format does only work with std::fixed with MSVC2008 or above.
// See https://bugzilla.gnome.org/show_bug.cgi?id=599340
#if !defined(_MSC_VER) || _MSC_VER >= 1500
<< ustring::compose("%1 € are %3 %% of %2 €.", a, b,
ustring::format(std::fixed, std::setprecision(1), a / b * 100.0))
<< std::endl
#endif
<< ustring::compose("a : b = [%1|%2]",
ustring::format(std::setfill(L'a'), std::setw(i), ""),
ustring::format(std::setfill(L'b'), std::setw(40 - i), ""))
<< std::endl;
}
} // anonymous namespace
int
main(int, char**)
{
std::locale::global(std::locale(""));
std::cout.imbue(std::locale());
Glib::init();
show_examples();
return 0;
}
|