Nice, no more exception, but it behaves a bit wierdish. Let me just show you the output, this code:
EDIT: I'm too hasty, so I write before I think, but now I as I was writing I figured out the problem (it was with the 'n' variable). Thanks PanGalactic.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
for (i = 0, j = 0, n = 0; i < sBuf.size(); i++)
{
if (sBuf.at(i) == ',' && n != 0)
{
j++;
n = 0;
}
elseif (!(sBuf.at(i) == ',' || sBuf.at(i) == '"'))
{
sNames[j].push_back(sBuf.at(i));
}
else
;
getchar();
fflush(stdin);
cout << sNames[j];
}
generates:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
M
MA
MAR
MARY
MARYP
MARYPA
MARYPAT
MARYPATR
MARYPATRI
MARYPATRIC
MARYPATRICI
MARYPATRICIA
MARYPATRICIAL
MARYPATRICIALI
MARYPATRICIALIN
MARYPATRICIALIND
MARYPATRICIALINDA
But it should be something more like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
M
MA
MAR
MARY
P
PA
PAT
PATR
PATRI
PATRIC
PATRICI
PATRICIA
L
LI
LIN
LIND
LINDA
I think this bit of code
1 2 3 4 5
if (sBuf.at(i) == ',' && n != 0)
{
j++;
n = 0;
}
is suppose to jump to the next string as it sees a ','.