Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends largely on the semantics of those <code>int</code>s. If they're descrete values (say the results of throwing 1000&ndahs;10000 ten sided dice), then something like:</p> <pre><code>std::ostream&amp; operator&lt;&lt;( std::ostream&amp; dest, std::vector&lt;int&gt; const&amp; source ) { dest &lt;&lt; '['; for ( std::vector&lt;int&gt;::const_iterator current = source.begin(); current != source.end(); ++ current ) { if ( current != source.begin() ) { dest &lt;&lt; ", "; } dest &lt;&lt; *current; } dest &lt;&lt; ']'; return dest; } </code></pre> <p>might do the trick; more likely, you'd want to pick up <code>dest.width()</code>, and set it before the output of each int (or treat it as the total width, and work out how much padding you need per <code>int</code>, and set that before outputting each int), and you also might want to insert line breaks.</p> <p>If, on the other hand, your vector is a single number in base 10, with one digit per <code>int</code> (in which case, I'd recommend using <code>char</code>, rather than int), you want something like:</p> <pre><code>std::ostream&amp; operator&lt;&lt;( std::ostream&amp; dest, std::vector&lt;int&gt; const&amp; source ) { std::vector&lt;int&gt;::const_reverse_iterator current = std::find_if( source.rbegin(), source.rend(), boost::bind( std::not_equal_to&lt;int&gt;(), _1, 0 ) ); if ( current == source.rend() ) { dest &lt;&lt; '0'; } else { while ( current != source.rend() ) { dest &lt;&lt; *current + '0'; ++ current; } } return dest; } </code></pre> <p>(This is for a little endian representation; for bigendian, replace the reverse iterators with normal iterators.)</p> <p>Again, you'll probably want to handle <code>width()</code> and <code>fill()</code>; handling the base would be significantly more difficult.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload