• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Stream Parsers (stream, wstream, etc.)</title>
5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8">
8<link rel="up" href="../stream.html" title="Stream Parsers">
9<link rel="prev" href="../stream.html" title="Stream Parsers">
10<link rel="next" href="../string.html" title="String Parsers">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../stream.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stream.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../string.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="spirit.qi.reference.stream.stream"></a><a class="link" href="stream.html" title="Stream Parsers (stream, wstream, etc.)">Stream Parsers
28          (<code class="computeroutput"><span class="identifier">stream</span></code>, <code class="computeroutput"><span class="identifier">wstream</span></code>, etc.)</a>
29</h5></div></div></div>
30<h6>
31<a name="spirit.qi.reference.stream.stream.h0"></a>
32            <span class="phrase"><a name="spirit.qi.reference.stream.stream.description"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.description">Description</a>
33          </h6>
34<p>
35            The <code class="computeroutput"><span class="identifier">stream_parser</span></code> is
36            a primitive which allows to use pre-existing standard streaming operators
37            for input parsing integrated with <span class="emphasis"><em>Spirit.Qi</em></span>. It
38            provides a wrapper parser dispatching the underlying input stream to
39            the stream operator of the corresponding attribute type to be parsed.
40            Any value <code class="computeroutput"><span class="identifier">a</span></code> to be parsed
41            using the <code class="computeroutput"><span class="identifier">stream_parser</span></code>
42            will result in invoking the standard streaming operator for its type
43            <code class="computeroutput"><span class="identifier">A</span></code>, for instance:
44          </p>
45<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">istream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&gt;&gt;</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">istream</span><span class="special">&amp;,</span> <span class="identifier">A</span><span class="special">&amp;);</span>
46</pre>
47<h6>
48<a name="spirit.qi.reference.stream.stream.h1"></a>
49            <span class="phrase"><a name="spirit.qi.reference.stream.stream.header"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.header">Header</a>
50          </h6>
51<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/qi/stream.hpp&gt;</span>
52<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_stream</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
53</pre>
54<p>
55            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
56          </p>
57<h6>
58<a name="spirit.qi.reference.stream.stream.h2"></a>
59            <span class="phrase"><a name="spirit.qi.reference.stream.stream.namespace"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.namespace">Namespace</a>
60          </h6>
61<div class="informaltable"><table class="table">
62<colgroup><col></colgroup>
63<thead><tr><th>
64                    <p>
65                      Name
66                    </p>
67                  </th></tr></thead>
68<tbody>
69<tr><td>
70                    <p>
71                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">stream</span> <span class="comment">//
72                      alias: boost::spirit::qi::stream</span></code>
73                    </p>
74                  </td></tr>
75<tr><td>
76                    <p>
77                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">wstream</span> <span class="comment">//
78                      alias: boost::spirit::qi::wstream</span></code>
79                    </p>
80                  </td></tr>
81</tbody>
82</table></div>
83<h6>
84<a name="spirit.qi.reference.stream.stream.h3"></a>
85            <span class="phrase"><a name="spirit.qi.reference.stream.stream.synopsis"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.synopsis">Synopsis</a>
86          </h6>
87<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Char</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attrib</span><span class="special">&gt;</span>
88<span class="keyword">struct</span> <span class="identifier">stream_parser</span><span class="special">;</span>
89</pre>
90<h6>
91<a name="spirit.qi.reference.stream.stream.h4"></a>
92            <span class="phrase"><a name="spirit.qi.reference.stream.stream.template_parameters"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.template_parameters">Template
93            parameters</a>
94          </h6>
95<div class="informaltable"><table class="table">
96<colgroup>
97<col>
98<col>
99<col>
100</colgroup>
101<thead><tr>
102<th>
103                    <p>
104                      Parameter
105                    </p>
106                  </th>
107<th>
108                    <p>
109                      Description
110                    </p>
111                  </th>
112<th>
113                    <p>
114                      Default
115                    </p>
116                  </th>
117</tr></thead>
118<tbody>
119<tr>
120<td>
121                    <p>
122                      <code class="computeroutput"><span class="identifier">Char</span></code>
123                    </p>
124                  </td>
125<td>
126                    <p>
127                      The character type to use to generate the input. This type
128                      will be used while assigning the generated characters to the
129                      underlying input iterator.
130                    </p>
131                  </td>
132<td>
133                    <p>
134                      <code class="computeroutput"><span class="keyword">char</span></code>
135                    </p>
136                  </td>
137</tr>
138<tr>
139<td>
140                    <p>
141                      <code class="computeroutput"><span class="identifier">Attrib</span></code>
142                    </p>
143                  </td>
144<td>
145                    <p>
146                      The type of the attribute the <code class="computeroutput"><span class="identifier">stream_parser</span></code>
147                      is expected to parse its input into.
148                    </p>
149                  </td>
150<td>
151                    <p>
152                      <code class="computeroutput"><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">basic_hold_any</span><span class="special">&lt;</span><span class="identifier">Char</span><span class="special">&gt;</span></code>
153                    </p>
154                  </td>
155</tr>
156</tbody>
157</table></div>
158<h6>
159<a name="spirit.qi.reference.stream.stream.h5"></a>
160            <span class="phrase"><a name="spirit.qi.reference.stream.stream.model_of"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.model_of">Model
161            of</a>
162          </h6>
163<div class="blockquote"><blockquote class="blockquote"><p>
164              <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>
165            </p></blockquote></div>
166<div class="variablelist">
167<p class="title"><b>Notation</b></p>
168<dl class="variablelist">
169<dt><span class="term"><code class="computeroutput"><span class="identifier">s</span></code></span></dt>
170<dd><p>
171                  A variable instance of any type with a defined matching streaming
172                  <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code>
173                  or a <a class="link" href="../basics.html#spirit.qi.reference.basics.lazy_argument">Lazy
174                  Argument</a> that evaluates to any type with a defined matching
175                  streaming <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code>.
176                </p></dd>
177</dl>
178</div>
179<h6>
180<a name="spirit.qi.reference.stream.stream.h6"></a>
181            <span class="phrase"><a name="spirit.qi.reference.stream.stream.expression_semantics"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.expression_semantics">Expression
182            Semantics</a>
183          </h6>
184<p>
185            Semantics of an expression is defined only where it differs from, or
186            is not defined in <a class="link" href="../parser_concepts/primitiveparser.html" title="PrimitiveParser"><code class="computeroutput"><span class="identifier">PrimitiveParser</span></code></a>.
187          </p>
188<div class="informaltable"><table class="table">
189<colgroup>
190<col>
191<col>
192</colgroup>
193<thead><tr>
194<th>
195                    <p>
196                      Expression
197                    </p>
198                  </th>
199<th>
200                    <p>
201                      Description
202                    </p>
203                  </th>
204</tr></thead>
205<tbody>
206<tr>
207<td>
208                    <p>
209                      <code class="computeroutput"><span class="identifier">stream</span></code>
210                    </p>
211                  </td>
212<td>
213                    <p>
214                      Call the streaming <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code> for the type of the
215                      mandatory attribute. The input recognized by this operator
216                      will be the result of the <code class="computeroutput"><span class="identifier">stream</span></code>
217                      parser. This parser never fails (unless the underlying input
218                      stream reports an error). The character type of the I/O istream
219                      is assumed to be <code class="computeroutput"><span class="keyword">char</span></code>.
220                    </p>
221                  </td>
222</tr>
223<tr>
224<td>
225                    <p>
226                      <code class="computeroutput"><span class="identifier">wstream</span></code>
227                    </p>
228                  </td>
229<td>
230                    <p>
231                      Call the streaming <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code> for the type of the
232                      mandatory attribute. The input recognized by this operator
233                      will be the result of the <code class="computeroutput"><span class="identifier">wstream</span></code>
234                      parser. This parser never fails (unless the underlying input
235                      stream reports an error). The character type of the I/O istream
236                      is assumed to be <code class="computeroutput"><span class="keyword">wchar_t</span></code>.
237                    </p>
238                  </td>
239</tr>
240</tbody>
241</table></div>
242<p>
243            All parsers listed in the table above are predefined specializations
244            of the <code class="computeroutput"><span class="identifier">stream_parser</span><span class="special">&lt;</span><span class="identifier">Char</span><span class="special">&gt;</span></code> basic stream parser type described
245            below. It is possible to directly use this type to create stream parsers
246            using an arbitrary underlying character type.
247          </p>
248<div class="informaltable"><table class="table">
249<colgroup>
250<col>
251<col>
252</colgroup>
253<thead><tr>
254<th>
255                    <p>
256                      Expression
257                    </p>
258                  </th>
259<th>
260                    <p>
261                      Semantics
262                    </p>
263                  </th>
264</tr></thead>
265<tbody><tr>
266<td>
267                    <p>
268</p>
269<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">stream_parser</span><span class="special">&lt;</span>
270    <span class="identifier">Char</span><span class="special">,</span> <span class="identifier">Attrib</span>
271<span class="special">&gt;()</span></pre>
272<p>
273                    </p>
274                  </td>
275<td>
276                    <p>
277                      Call the streaming <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code> for the type of the
278                      optional attribute, <code class="computeroutput"><span class="identifier">Attrib</span></code>.
279                      The input recognized by this operator will be the result of
280                      the <code class="computeroutput"><span class="identifier">stream_parser</span><span class="special">&lt;&gt;</span></code> parser. This parser
281                      never fails (unless the underlying input stream reports an
282                      error). The character type of the I/O istream is assumed to
283                      be <code class="computeroutput"><span class="identifier">Char</span></code>
284                    </p>
285                  </td>
286</tr></tbody>
287</table></div>
288<h6>
289<a name="spirit.qi.reference.stream.stream.h7"></a>
290            <span class="phrase"><a name="spirit.qi.reference.stream.stream.additional_requirements"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.additional_requirements">Additional
291            Requirements</a>
292          </h6>
293<p>
294            All of the stream parsers listed above require the type of the value
295            to parse (the associated attribute) to implement a streaming operator
296            conforming to the usual I/O streams conventions (where <code class="computeroutput"><span class="identifier">attribute_type</span></code> is the type of the value
297            to recognize while parse):
298          </p>
299<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Istream</span><span class="special">&gt;</span>
300<span class="identifier">Istream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&gt;&gt;</span> <span class="special">(</span><span class="identifier">Istream</span><span class="special">&amp;</span> <span class="identifier">os</span><span class="special">,</span> <span class="identifier">attribute_type</span><span class="special">&amp;</span> <span class="identifier">attr</span><span class="special">)</span>
301<span class="special">{</span>
302    <span class="comment">// type specific input parsing</span>
303    <span class="keyword">return</span> <span class="identifier">os</span><span class="special">;</span>
304<span class="special">}</span>
305</pre>
306<p>
307            This operator will be called by the stream parsers to gather the input
308            for the attribute of type <code class="computeroutput"><span class="identifier">attribute_type</span></code>.
309          </p>
310<div class="note"><table border="0" summary="Note">
311<tr>
312<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
313<th align="left">Note</th>
314</tr>
315<tr><td align="left" valign="top"><p>
316              If the <code class="computeroutput"><span class="identifier">stream</span></code> parser
317              is invoked inside a <a class="link" href="../parse_api/stream_api.html" title="Stream Based Parser API"><code class="computeroutput"><span class="identifier">match</span></code></a> (or <a class="link" href="../parse_api/stream_api.html" title="Stream Based Parser API"><code class="computeroutput"><span class="identifier">phrase_match</span></code></a>) stream manipulator
318              the <code class="computeroutput"><span class="identifier">Istream</span></code> passed
319              to the <code class="computeroutput"><span class="keyword">operator</span><span class="special">&gt;&gt;()</span></code>
320              will have registered (imbued) the same standard locale instance as
321              the stream the <a class="link" href="../parse_api/stream_api.html" title="Stream Based Parser API"><code class="computeroutput"><span class="identifier">match</span></code></a> (or <a class="link" href="../parse_api/stream_api.html" title="Stream Based Parser API"><code class="computeroutput"><span class="identifier">phrase_match</span></code></a>) manipulator
322              has been used with. This ensures all facets registered (imbued) with
323              the original I/O stream object are used during input parsing.
324            </p></td></tr>
325</table></div>
326<h6>
327<a name="spirit.qi.reference.stream.stream.h8"></a>
328            <span class="phrase"><a name="spirit.qi.reference.stream.stream.attributes"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.attributes">Attributes</a>
329          </h6>
330<div class="informaltable"><table class="table">
331<colgroup>
332<col>
333<col>
334</colgroup>
335<thead><tr>
336<th>
337                    <p>
338                      Expression
339                    </p>
340                  </th>
341<th>
342                    <p>
343                      Attribute
344                    </p>
345                  </th>
346</tr></thead>
347<tbody>
348<tr>
349<td>
350                    <p>
351                      <code class="computeroutput"><span class="identifier">stream</span></code>
352                    </p>
353                  </td>
354<td>
355                    <p>
356                      <code class="computeroutput"><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">hold_any</span></code>
357                    </p>
358                  </td>
359</tr>
360<tr>
361<td>
362                    <p>
363                      <code class="computeroutput"><span class="identifier">wstream</span></code>
364                    </p>
365                  </td>
366<td>
367                    <p>
368                      <code class="computeroutput"><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">whold_any</span></code>
369                    </p>
370                  </td>
371</tr>
372<tr>
373<td>
374                    <p>
375                      <code class="computeroutput"><span class="identifier">stream_parser</span><span class="special">&lt;</span><span class="identifier">Char</span><span class="special">,</span> <span class="identifier">Attrib</span><span class="special">&gt;()</span></code>
376                    </p>
377                  </td>
378<td>
379                    <p>
380                      <code class="computeroutput"><span class="identifier">Attrib</span></code>
381                    </p>
382                  </td>
383</tr>
384</tbody>
385</table></div>
386<div class="important"><table border="0" summary="Important">
387<tr>
388<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../images/important.png"></td>
389<th align="left">Important</th>
390</tr>
391<tr><td align="left" valign="top"><p>
392              The attribute type <code class="computeroutput"><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">hold_any</span></code>
393              exposed by some of the stream parsers is semantically and syntactically
394              equivalent to the type implemented by <a href="../../../../../../../../libs/any/index.html" target="_top">Boost.Any</a>.
395              It has been added to <span class="emphasis"><em>Spirit</em></span> as it has better performance
396              and a smaller footprint than <a href="../../../../../../../../libs/any/index.html" target="_top">Boost.Any</a>.
397            </p></td></tr>
398</table></div>
399<h6>
400<a name="spirit.qi.reference.stream.stream.h9"></a>
401            <span class="phrase"><a name="spirit.qi.reference.stream.stream.complexity"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.complexity">Complexity</a>
402          </h6>
403<div class="blockquote"><blockquote class="blockquote"><p>
404              O(N), where N is the number of characters consumed by the stream parser
405            </p></blockquote></div>
406<h6>
407<a name="spirit.qi.reference.stream.stream.h10"></a>
408            <span class="phrase"><a name="spirit.qi.reference.stream.stream.example"></a></span><a class="link" href="stream.html#spirit.qi.reference.stream.stream.example">Example</a>
409          </h6>
410<div class="note"><table border="0" summary="Note">
411<tr>
412<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
413<th align="left">Note</th>
414</tr>
415<tr><td align="left" valign="top"><p>
416              The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a>
417              section.
418            </p></td></tr>
419</table></div>
420<p>
421            A class definition used in the examples:
422          </p>
423<p>
424</p>
425<pre class="programlisting"><span class="comment">// a simple complex number representation z = a + bi</span>
426<span class="keyword">struct</span> <span class="identifier">complex</span>
427<span class="special">{</span>
428    <span class="identifier">complex</span> <span class="special">(</span><span class="keyword">double</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">)</span>
429      <span class="special">:</span> <span class="identifier">a</span><span class="special">(</span><span class="identifier">a</span><span class="special">),</span> <span class="identifier">b</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span>
430    <span class="special">{}</span>
431
432    <span class="keyword">double</span> <span class="identifier">a</span><span class="special">;</span>
433    <span class="keyword">double</span> <span class="identifier">b</span><span class="special">;</span>
434<span class="special">};</span>
435</pre>
436<p>
437          </p>
438<p>
439</p>
440<pre class="programlisting"><span class="comment">// define streaming operator for the type complex</span>
441<span class="identifier">std</span><span class="special">::</span><span class="identifier">istream</span><span class="special">&amp;</span>
442<span class="keyword">operator</span><span class="special">&gt;&gt;</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">istream</span><span class="special">&amp;</span> <span class="identifier">is</span><span class="special">,</span> <span class="identifier">complex</span><span class="special">&amp;</span> <span class="identifier">z</span><span class="special">)</span>
443<span class="special">{</span>
444    <span class="keyword">char</span> <span class="identifier">lbrace</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">,</span> <span class="identifier">comma</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">,</span> <span class="identifier">rbrace</span> <span class="special">=</span> <span class="char">'\0'</span><span class="special">;</span>
445    <span class="identifier">is</span> <span class="special">&gt;&gt;</span> <span class="identifier">lbrace</span> <span class="special">&gt;&gt;</span> <span class="identifier">z</span><span class="special">.</span><span class="identifier">a</span> <span class="special">&gt;&gt;</span> <span class="identifier">comma</span> <span class="special">&gt;&gt;</span> <span class="identifier">z</span><span class="special">.</span><span class="identifier">b</span> <span class="special">&gt;&gt;</span> <span class="identifier">rbrace</span><span class="special">;</span>
446    <span class="keyword">if</span> <span class="special">(</span><span class="identifier">lbrace</span> <span class="special">!=</span> <span class="char">'{'</span> <span class="special">||</span> <span class="identifier">comma</span> <span class="special">!=</span> <span class="char">','</span> <span class="special">||</span> <span class="identifier">rbrace</span> <span class="special">!=</span> <span class="char">'}'</span><span class="special">)</span>
447        <span class="identifier">is</span><span class="special">.</span><span class="identifier">setstate</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failbit</span><span class="special">);</span>
448    <span class="keyword">return</span> <span class="identifier">is</span><span class="special">;</span>
449<span class="special">}</span>
450</pre>
451<p>
452          </p>
453<p>
454            Using declarations and variables:
455          </p>
456<p>
457</p>
458<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">stream</span><span class="special">;</span>
459<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">qi</span><span class="special">::</span><span class="identifier">stream_parser</span><span class="special">;</span>
460</pre>
461<p>
462          </p>
463<p>
464            Parse a simple string using the operator&gt;&gt;(istream&amp;, std::string&amp;);
465          </p>
466<p>
467</p>
468<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">;</span>
469<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"abc"</span><span class="special">,</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">str</span><span class="special">);</span>
470<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">str</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>                  <span class="comment">// prints: abc</span>
471</pre>
472<p>
473          </p>
474<p>
475            Parse our complex type using the operator&gt;&gt;(istream&amp;, complex&amp;);
476          </p>
477<p>
478</p>
479<pre class="programlisting"><span class="identifier">complex</span> <span class="identifier">c</span><span class="special">;</span>
480<span class="identifier">test_parser_attr</span><span class="special">(</span><span class="string">"{1.0,2.5}"</span><span class="special">,</span> <span class="identifier">stream_parser</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">complex</span><span class="special">&gt;(),</span> <span class="identifier">c</span><span class="special">);</span>
481<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">a</span> <span class="special">&lt;&lt;</span> <span class="string">","</span> <span class="special">&lt;&lt;</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">b</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>    <span class="comment">// prints: 1.0,2.5</span>
482</pre>
483<p>
484          </p>
485</div>
486<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
487<td align="left"></td>
488<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
489        Distributed under the Boost Software License, Version 1.0. (See accompanying
490        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
491      </p>
492</div></td>
493</tr></table>
494<hr>
495<div class="spirit-nav">
496<a accesskey="p" href="../stream.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stream.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../string.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
497</div>
498</body>
499</html>
500