Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
num_get.cpp
Go to the documentation of this file.
1
29#include <iostream> // for cout, endl
30#include <sstream> // for istringstream
31#include <string> // for string
32
33
34int main ()
35{
36 typedef std::istreambuf_iterator<char, std::char_traits<char> > Iter;
37
38 std::ios::iostate state;
39 Iter end;
40
41 bool bval = false;
42 long lval = 0L;
43 long double ldval = 0.0;
44
45 const std::locale loc;
46
47 // Get a num_get facet
48 const std::num_get<char, Iter> &ng =
49 std::use_facet<std::num_get<char, Iter> >(loc);
50
51#ifndef _RWSTD_NO_BOOL
52 {
53 // Build an istringstream from the buffer and construct
54 // beginning and ending iterators on it.
55 std::istringstream ins ("true");
56 Iter begin (ins);
57
58 // Set stream flags to recognize boolalpha input.
59 ins.setf (std::ios::boolalpha);
60
61 // Get the boolean value from the stream.
62 ng.get (begin, end, ins, state, bval);
63 }
64#endif
65
66 std::cout << bval << std::endl;
67
68 {
69 // Get the date
70 std::istringstream ins ("2422235");
71 Iter begin (ins);
72 ng.get (begin, end, ins, state, lval);
73 }
74
75 std::cout << lval << std::endl;
76
77 {
78 // Get the weekday
79 std::istringstream ins ("32324342.98908");
80 Iter begin (ins);
81 ng.get (begin, end, ins, state, ldval);
82 }
83
84 std::cout.setf (std::ios::fixed, std::ios::floatfield);
85 std::cout << ldval << std::endl;
86
87 return 0;
88}
#define loc
Definition 17.names.cpp:492
#define L
Definition 17.names.cpp:155
const int end
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition num_get.cpp:34