Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have several issues, addressed below:</p> <pre><code>int main() { std::string line; std::ifstream infile ("Input.csv"); std::vector&lt;std::string&gt; table; while (std::getline(infile, line)) // this is the loop you want to read the file { std::istringstream iss(line); std::string word; while (std::getline(iss, word, ',')) // there are better ways to do this, but this will work { table.push_back(word); } } for(int index=0; index&lt;table.size(); ++index) // loop through the whole size { std::cout&lt;&lt; "Element" &lt;&lt; index &lt;&lt; ":" &lt;&lt; table[index] &lt;&lt; std::endl ; } infile.close(); return 0; } </code></pre> <p>Alternatively, you can avoid the use of nested while loops altogether:</p> <pre><code>struct csv_reader : std::ctype&lt;char&gt; { csv_reader() : std::ctype&lt;char&gt;(get_table()) {} static std::ctype_base::mask const* get_table() { static std::vector&lt;std::ctype_base::mask&gt; rc(table_size, std::ctype_base::mask()); rc['\n'] = std::ctype_base::space; rc[','] = std::ctype_base::space; return &amp;rc[0]; } }; int main() { std::string line; std::ifstream infile ("Input.csv"); csv_reader reader; infile.imbue(std::locale(std::locale(), &amp;reader); std::vector&lt;std::string&gt; table{std::istream_iterator&lt;std::string&gt;(infile), std::istream_iterator&lt;std::string&gt;()}; // or //std::vector&lt;std::string&gt; table; //std::copy(std::istream_iterator&lt;std::string&gt;(infile), std::istream_iterator&lt;std::string&gt;(), std::back_inserter(table)); for(int index=0; index&lt;table.size(); ++index) // loop through the whole size { std::cout&lt;&lt; "Element" &lt;&lt; index &lt;&lt; ":" &lt;&lt; table[index] &lt;&lt; std::endl ; } infile.close(); return 0; } </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.
 

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