Assignment of string to structure element

后端 未结 5 2071
长情又很酷
长情又很酷 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:37

    In C++ use 'new' instead of 'malloc'. Using malloc does not run the constructor of your class, so the string is not initialized.

提交回复
热议问题