-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathformat.cpp
69 lines (48 loc) · 1.26 KB
/
format.cpp
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
62
63
64
65
66
67
68
// Copyright (c) 2015
// Author: Chrono Law
#include <std.hpp>
using namespace std;
#include <boost/format.hpp>
using namespace boost;
//////////////////////////////////////////
void case1()
{
cout << format("%s:%d+%d=%d\n") %"sum" % 1 % 2 % (1+2);
format fmt("(%1% + %2%) * %2% = %3%\n");
fmt % 2 % 5 ;
fmt % ((2+5)*5);
cout << fmt.str();
}
//////////////////////////////////////////
void case2()
{
format fmt("%05d\t%-8.3f\t% 10s\t%05X\n");
cout << fmt %62 % 2.236 % "123456789" % 48;
format fmt2("%|05d|\t%|-8.3f|\t%| 10s|\t%|05X|\n");
cout << fmt2 %62 % 2.236 % "123456789" % 48;
const format fmt3("%10d %020.8f %010X %10.5e\n");
cout << format(fmt3) %62 % 2.236 % 255 % 0.618;
}
//////////////////////////////////////////
#include <iomanip>
using namespace boost;
using boost::io::group;
void case3()
{
format fmt("%1% %2% %3% %2% %1% \n");
cout << fmt %1 % 2 % 3;
fmt.bind_arg(2, 10);
cout << fmt %1 %3;
fmt.clear();
cout << fmt % group(showbase,oct, 111) % 333;
fmt.clear_binds();
fmt.modify_item(1, group(hex, right, showbase,setw(8), setfill('*')));
cout << fmt % 49 % 20 % 100;
}
//////////////////////////////////////////
int main()
{
case1();
case2();
case3();
}