Note that there are some explanatory texts on larger screens.

plurals
  1. POGetline reading in a csv very oddly
    primarykey
    data
    text
    <p>I am trying to read a csv using get line to extract three variables separated by commas. Name, Course, and Grade.</p> <p>I am reading in the first line fine but it puts in weird new line breaks and sends the format into a cluster.</p> <p>Here is my code :</p> <pre><code>#include "header.h" string student::GetCourse() { return course; } string student::GetName() { return name; } string student::GetGrade() { return grade; } void student::setname(string n) { name = n; } void student::setCourse(string c) { course = c; } void student::setGrade(string g) { grade = g; } void sort (vector &lt;student&gt; &amp;List) { student temp; int first = 1; int vectorLength = List.size() - 1; for (int i = vectorLength; i &gt; 0; i--) { first = i; for (int j = 0; j &lt; i; j++) { if (List[j].GetName() &gt; List[first].GetName()) first = j; } temp = List[first]; List[first] = List[i]; List[i] = temp; } } void main () { ifstream file; vector &lt;student&gt; StudentList; file.open("short.txt"); while (!file.eof()) { file.ignore(8196,'\n'); string tempname, tempgrade, tempcourse = ""; if (file != "\n") { getline(file, tempname, ','); getline(file, tempcourse, ','); getline(file, tempgrade, ','); } student s; s.setCourse(tempcourse); s.setname (tempname); s.setGrade (tempgrade); StudentList.push_back(s); } //sort (StudentList); for (int i = 0; i &lt; StudentList.size(); i++) { cout &lt;&lt; StudentList[i].GetName() &lt;&lt; " " &lt;&lt; StudentList[i].GetCourse() &lt;&lt; " " &lt;&lt; StudentList[i].GetGrade() &lt;&lt; endl; } } </code></pre> <p>Any ideas, I am having a real hard time on reading in this file.</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.
 

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