How to fill populate vector struct?

Hi all,

I'm trying to fill up my vector like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <ssqls.h>

sql_create_6(my_ssqls,
	1, 6, // The meaning of these values is covered in the user manual
	mysqlpp::sql_int, users_id,
	mysqlpp::sql_char, name,
	mysqlpp::sql_char, method,
	mysqlpp::sql_int, mode_id)

....


std::vector<my_ssqls> rows;

for(size_t i = 0; i < rowSize; i++) {
    rows[i].users_id = 6788;
  .....etc....
}


But my program terminates unexpectedly when it gets to the line where it has to populate the vector rows[i].users_id = 6788;

Any help?
The vector's size is initially zero. If you want to add and grow the vector one item at a time, you can use push_back. In your case, you already know how many items you want to store, so just resize the vector to be the right size.
1
2
3
4
5
6
std::vector<my_ssqls> rows;
rows.resize(rowSize);
for(size_t i = 0; i < rowSize; ++i) {
    rows[i].users_id = 6788;
    // .....etc....
}
Hi kbw,

Thanks! That worked a treat. Bit silly of me really..

Topic archived. No new replies allowed.