Reading a CSV file into an array of struct problem (again!)

GLW

Joined
Dec 13, 2010
Messages
3
Reaction score
0
Posted this yesterday, 16 people looked but nobody was willing to help me out. I'll try again.....

Hi, new to this and have looked through previous posts to see if I can make sense of what’s going wrong but to no avail, any help would be appreciated.

I am attempting to read csv data into an array of struct.
The csv data has the following form:

11/05/2010;12:37:01;36;687;686.7;686.7;687.23

I’ve setup my struct as follows:

struct infile_t {
string Day;
string CaptureTime;
int Volume;
float Open;
float Close;
float Min;
float Max;
} DataArr[2000];

I read in each csv value and attempt to append it to the corresponding members of the struct as follows:
getline(b_file,DataArr.Day,';');
getline(b_file,DataArr.CaptureTime,';');
getline(b_file,mystr,';');
stringstream(mystr) >> DataArr.Volume;
getline(b_file,mystr,';');
stringstream(mystr) >> DataArr.Open;
getline(b_file,mystr,';');
stringstream(mystr) >> DataArr.Close;
getline(b_file,mystr,';');
stringstream(mystr) >> DataArr.Min;
getline(b_file,mystr);
stringstream(mystr) >> DataArr.Max;

however, if I try to print the contents of say the first set of elements in the struct I get the following:

11/05/2010
12:37:01
0
0
0
0
0

I am assuming that there’s problem with my attempt to convert the string into an integer/float data type?
Could someone point me in the right direction?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top