Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since this is tagged as C++, the most obvious way would be using streams. Off the top of my head, something like this might do: </p> <pre><code>std::vector&lt;float&gt; readFile(std::istream&amp; is) { char chdummy; is &gt;&gt; std::ws &gt;&gt; chdummy &gt;&gt; std::ws; if(!is || chdummy != '*') error(); std::string strdummy; std::getline(is,strdummy,':'); if(!is || strdummy != "SZA") error(); std::vector&lt;float&gt; result; for(;;) { float number; if( !is&gt;&gt;number ) break; result.push_back(number); } if( !is.eof() ) error(); return result; } </code></pre> <p>Why <code>float</code>, BTW? Usually, <code>double</code> is much better. </p> <p><em>Edit</em>, since it was questioned whether returning a copy of the <code>vector</code> is a good idea: </p> <p>For a first solution, I'd certainly do the obvious. The function <em>is</em> reading a file into a <code>vector</code>, and the most obvious thing for a function to do is to return its result. Whether this results in a noticeable slowdown depends on a lot of things (the size of the vector, how often the function is called and from where, the speed of the disk this reads from, whether the compiler can apply RVO). I wouldn't want to spoil the obvious solution with an optimization, but if profiling indeed shows that this is to slow, the vector should be passed in per non-const reference. </p> <p>(Also note that C++1x with rvalue support, hopefully soon to be available by means of a compiler near you, will render this discussion moot, as it will prevent the vector from being copied upon returning from the function.) </p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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