![]() |
|
#1
|
|||
|
|||
Trying to make a vector of structures, need helpHello,
I am writing a program that runs a bunch of statistical tests on data that is read in from a file. What I am having trouble with is storing the data in structures. There is a data file that has rows of scores. Right now, the program reads in each row as a string, splits the strings up, and converts each value to a float. Each float is stored as a value in a vector. So a string like: "11 1 1 111 111 1" Becomes a vector with 6 elements, each one holding a float. What I ideally want is to have something like this. DATASET -GROUPS -SCORES CPP / C++ / C Code:
This is the code that I have working for the string conversion to a float of vectors: CPP / C++ / C Code:
What I cannot figure out is how to assign the values from the newvect vector into a vector that is a member of a group structure, that is part of a vector of group structures, in the dataset structure. I thought that I could do it like this: CPP / C++ / C Code:
..but that gives me an error saying "expected initializer before '.' token", which I don't understand. I had thought that it would step through the data.groups vector of group structures, and pass each one into the fuction I wrote that assigns values to the vector of floats, but it doesn't. I think maybe I am not initializing something right, but I don't know what Any help would be sincerely appreciated!! |
|
#2
|
|||
|
|||
|
For reference, this is the function I wrote that passes values into the vector of floats of a group structure:
CPP / C++ / C Code:
The iteration of five and value of one are arbitray, I was just using it for testing. This function works great if I run it like this: CPP / C++ / C Code:
I will get a cow structure that gets the value of 1 assigned to vector elements 0 through 5. What I cannot do is get it to "fill" a structure that is part of a vector of structures. i.e. CPP / C++ / C Code:
It will compile and run, but the code above doesn't execute, and I get an "exited due to signal 10 (SIGBUS)" error. |
|
#3
|
|||
|
|||
|
Quote:
CPP / C++ / C Code:
Maybe this, CPP / C++ / C Code:
If you have an idea of how many you need you could include that when make the vector. CPP / C++ / C Code:
Now you could do something like this for 20, CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
|
Thank you!!!!
I realized I wasn't initializing the groups properly, and ended up doing this: CPP / C++ / C Code:
The relevant part being: CPP / C++ / C Code:
I was totally flummoxed on using push_back to add a group, without having any values in it. Thank you again |
|
#5
|
|||
|
|||
|
Quote:
![]() |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Photoshop Tutorial: Make An Inspirational/Mystical Picture | ToddSAFM | Graphics Forum | 9 | 09-Aug-2005 21:32 |
| Delete and diplaying probrlem with structures. | glulu76 | C++ Forum | 2 | 09-May-2005 18:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The