newbie having problem with getline
Trying to read in a comma delimited text file and parse it into a string array xquestions [10][6].
Here's 2 lines of my text file...
line1- "Where is it found that Moses parted the Red Sea?,Joh 3:16,Gen 1,Exo 20,1Sa 17,Exo 14,Exo 14,"
line2- "Where is it found that Moses parted the Red Sea?,Joh 3:16,Gen 1,Exo 20,1Sa 17,Exo 14,Exo 14,Where is it found that David fought Goliath?,1Sa 17,1Ki 10,1Ki 20,1Sa 17,1Sa 10,1Sa 17,"
My code is....
Code:
ifstream xfile;
xfile.open(fileName);
if(!xfile.is_open()){
cout << "file failed to open" << endl;
}
xstring = "x";
int xrow=0;
int xcol=0;
while(!xfile.eof()){
for(xcol=0; xcol<=6; xcol++){
getline(xfile, xstring, ',');
if(xstring == " "){
break;
}
xquestions[xrow][xcol] = xstring;
}
xrow++;
But... after it runs and builds the array, the array[x][6] is filled with the first comma block of the next line.
I have tried and tried... but for the life of me, I cannot see where I fat fingered the code.
Could someone help me?