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
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