or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work?
This is my code to reference. Thanks!
try using the [getline] function on your [datafile] file stream to read an entire line out of the input file at a time.
once a line is read we should check if it has a comma in it - if so we should parse the line with comma logic otherwise we should parse it with space logic.
The second form will read up a specified delimiter.
Usually used in conjunction with stringstream to parse out integers, floats and doubles from the string just read.
(the rest is the same as above)
however now my output is only printing out my first policy. It looks like this: Premium for Pol1 is $14101.62
when it should look like this:
1 2 3 4
Premium for Pol1 is $14101.62
Premium for Pol2 is $14221.16
Premium for Pol3 is $582390.50
Premium for Pol4 is $220384.49
how come the while loop is stopping after the first policy? I want it to read all four
each field element retrieved by the getline statement on line 23 will retrieve each individual field, ie on first call it should return the policy, on second the gender, ...
your stringstream logic on line 24 where you pass through this field then doesn't seem correct.