~ubuntu-branches/ubuntu/gutsy/c++-annotations/gutsy

« back to all changes in this revision

Viewing changes to yo/concrete/examples/a2x.cc

  • Committer: Bazaar Package Importer
  • Author(s): Frank B. Brokken
  • Date: 2007-06-15 19:31:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615193112-i48grmnykrf1ipqf
Tags: 7.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 << endl;
 
17
 
 
18
    a2x = "err";
 
19
    d = a2x;                    // d is 0: the conversion failed,
 
20
    cout << d << endl;          // 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 << endl;          // 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 << endl;
 
31
//=
 
32
}
 
33
 
 
34
int expectsInt(int x)
 
35
{
 
36
    cout << x << endl;
 
37
    return x;
 
38
}