I'm trying to read a csv file that has the following contents:
1.00E+00,0.00E+00,5.70E-01
2.00E+00,5.00E-04,5.70E-01
3.00E+00,1.00E-03,5.70E-01
etc.
However, only the second and third elements of each row are read and stored into the arrays I pass the values to. I can't find what is wrong with the code. If I remove the while statement and repeat the lines under them for n times it works fine. Does anyone have a fix to this? Tired using fin.good() in the while conditions statement and it didn't work.
#include <iostream>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
string xcord;
string ycord;
string mole;
double m[100], tx[100], ty[100];
int i, k;
k = 0;
fstream fin;
fin.open("argon");
while(!fin.eof())
{
getline(fin,xcord,',');
getline(fin,ycord,',');
getline(fin,mole,'\n');
tx[k] = stod(xcord);
ty[k] = stod(ycord);
m[k] = stod(mole);
k++;
}
for(i=0;i<k;i++)
cout<<xcord<<"\t"<<ycord<<"\t"<<mole<<"\n";
return 0;
}