Debian Codegraph @

yo/concrete/examples/a2x.cc

raw
1 #include <iostream>
2 #include "a2x.h"
3
4 using namespace std;
5
6 // compile with a2xis.cc
7
8 int main()
9 {
10 //MAIN
11 int x = A2x{ "12" }; // initialize int x from a string "12"
12 A2x a2x{ "12.50" }; // explicitly create an A2x object
13
14 double d;
15 d = a2x; // assign a variable using an A2x object
16 cout << d << '\n';
17
18 a2x = "err";
19 d = a2x; // d is 0: the conversion failed,
20 cout << d << '\n'; // and a2x.good() == false
21
22 a2x = " a"; // reassign a2x to new text
23 char c = a2x; // c now 'a': internally operator>>() is used
24 cout << c << '\n'; // so initial blanks are skipped.
25
26 int expectsInt(int x); // initialize a parameter using an
27 expectsInt(A2x{ "1200" }); // anonymous A2x object
28
29 d = A2x{ "12.45" }.to<int>(); // d is 12, not 12.45
30 cout << d << '\n';
31 //=
32 }
33
34 int expectsInt(int x)
35 {
36 cout << x << '\n';
37 return x;
38 }