Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, you are trying to return a vector as strings. This won't work because they are different types and have no conversion defined from one to the other. Your function has the return type <code>string</code>.</p> <p><strong>Solution 1</strong></p> <p>In your case you could append the lines to a string instead of adding them to a vector? You are using the result as a string anyhow.</p> <p>You could change seqs to <code>string</code> and append data to it with the <code>+=</code> operator. </p> <p><strong>Solution 2</strong></p> <p>You could also change the return type to <code>vector&lt;string&gt;</code> but you would need to loop over the items and print them instead in your <code>main</code>. </p> <pre><code>vector&lt;string&gt; getseq(char * db_file) { ... return seqs; } </code></pre> <p><em>Caveat Lector: this will copy all the items. If you want to avoid this pass the vector as a reference to the function and add to it.</em></p> <p>Looping is quite easy using iterators:</p> <pre><code>// Get the strings as a vector. vector&lt;string&gt; seqs = getseq(argv[1]); // This is just a matter of taste, we create an alias for the vector&lt;string&gt; iterator type. typedef vector&lt;string&gt;:iterator_t string_iter; // Loop till we hit the end of the vector. for (string_iter i = seqs.begin(); i != seqs.end(); i++) { cout &lt;&lt; *i; // you could add endlines, commas here etc. } </code></pre> <hr> <p>If you want to avoid copying a vector and all the strings make <code>getseq</code> take a reference to a <code>vector&lt;string&gt;</code>.</p> <pre><code>void getseq(char * db_file, vector&lt;string&gt; &amp;seqs) { ... // vector&lt;string&gt; seqs; this line is not needed anymore. ... // we don't need to return anything anymore } </code></pre> <p>You would then need to create the <code>vector&lt;string&gt;</code> in your main instead, making my above code:</p> <pre><code>// Get the strings as a vector. vector&lt;string&gt; seqs; // Holds our strings. getseq(argv[1], seqs); // We don't return anything. // This is just a matter of taste, we create an alias for the vector&lt;string&gt; iterator type. typedef vector&lt;string&gt;:iterator_t string_iter; // Print prelude. cout &lt;&lt; "Sekwencje: \n"; // Loop till we hit the end of the vector. for (string_iter i = seqs.begin(); i != seqs.end(); i++) { cout &lt;&lt; *i &lt;&lt; " "; // Do processing, add endlines, commas here etc. } cout &lt;&lt; endl; </code></pre> <hr> <p><em>Edit after comments</em></p> <pre><code>int main(int argc, char * argv[1]) { // This is what you need, sorry for the confusion. // This copies the vector returned to seqs vector&lt;string&gt; seqs = getseq(argv[1]); // This is just a matter of taste, we create an alias for the vector&lt;string&gt; iterator type. typedef vector&lt;string&gt;::iterator string_iter; // Print prelude. cout &lt;&lt; "Sekwencje: \n"; // Loop till we hit the end of the vector. for (string_iter i = seqs.begin(); i != seqs.end(); i++) { cout &lt;&lt; *i &lt;&lt; " "; // Do processing, add endlines, commas here etc. } cout &lt;&lt; endl; } </code></pre>
    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. 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