Assignment of string to structure element

后端 未结 5 2043
长情又很酷
长情又很酷 2021-01-22 22:50

My program crashes when I try to assign a string value to a member of a structure. My suspicion is that the member (of type string) within the structure was never properly alloc

5条回答
  •  耶瑟儿~
    2021-01-22 23:33

    You have to create a new struct and not use malloc at all.

    So use:

    DataRow* node = new DataRow;
    

    you should also take care of cleaning it up like so:

    delete node;
    

    and in case you don't want to allocate it from the heap you can do this as well:

    DataRow node;
    

提交回复
热议问题