title: Reading a particular line in a csv file in C++
body: <p>I have a csv file which contains many rows of data. my function passes lineNum as an argument. So when a user enters 4 as lineNum I want to read the 4th line in the csv file. 
  I thought a good way to go through with this would be to look for \n 's and count them,stop when the count is lineNum-1, and then proceed to read the next line. 
  I think this is decent way of doing this, but I am thoroughly confused with the implementation. would love some help
  Here is my code </p>
  
  <pre><code>void ReadCsv( int lineNum){
      ifstream inFile ("/media/LOGGING/darsv1.csv");
      string line;
      string dataArray[226900];
      int i = 0;
      int endofline =0;
      int a, b, c, d, e;
      while (getline (inFile, line)) {
          //printf(line.c_str());
          istringstream linestream(line);
          string item ="";
          int itemnum = 0;
          if (lineNum==1) {
              printf(" line number is 1. ");
              while (getline (linestream, item, ',')) {
              itemnum++;
              dataArray[i]=item;
              i++;
              }
          }
          else {
              while (getline (linestream, item,'\n')) {
                  endofline=endofline+1;
                  cout&lt;&lt;"  went through line number  "&lt;&lt;endofline&lt;&lt;" ";
                  printf(" inside inner while, looking for line. ");
                  if (endofline == lineNum-1) {
                      printf(" found the correct line. ");
                      while (getline (linestream, item, ',')) {
                          itemnum++;
                          dataArray[i]=item;
                          i++;
                          printf(" found the correct data in the line. ");
                      }
                  }
              }printf(" out of inner while. ");
          }printf(" out of outer if. ");
     }
     printf(" out of all while loops. ");
  }
  </code></pre>