I am migrating codes with char data type to string, and below is my code:
struct SETTING_VALUE_LOCAL_SORT_LIST {
std::string top;
int id;
}
int list_table_size = 25;
LIST* setting_value = NULL;
setting_value = new LIST[list_table_size];
memset(setting_value, 0, (list_table_size * sizeof(LIST)));
std::cout << "set 1: \n";
setting_value[0].top = "test1";
setting_value[0].id = 1;
Can you please tell me why my program crashes after printing "set 1"? I seems there is an error accessing by element and need to access by the address set during memset. How should I do that?
Edit: Can you explain a little more, does that mean string cannot be in struct and then initialize?
Thanks in advanced.