| petergrwl (14) | |
|
how do i access vector data within a structure.? eg. struct coolstr { vector<int> var; }; ofstream output_file("test1.txt"); if (!output_file.fail()) { output_file << ??? (what would i put here to access the data in vector ? | |
|
|
|
| petergrwl (14) | |
|
if i use output_file << coolstr.var i get the fol error error: expected primary-expression before '.' token | |
|
|
|
| firedraco (4980) | |||
The reason you are getting that error is because "coolstr" is a type, not an instance. You need declare it like any other variable: coolstr somecoolstr;Anyway, an std::vector is basically an array so you use something like this to loop through the vector and get the information:
| |||
|
|
|||