Returning char* from function not working

前端 未结 3 579
Happy的楠姐
Happy的楠姐 2020-12-21 15:58

Visual studio c++ shows that \"string\" on line 24 has one array element, but the top contains all the text that was input by the user. But when I send to PutString(), it di

3条回答
  •  情歌与酒
    2020-12-21 16:05

    You are returning pointer to a variable that is local to the function in GetString(), when the function returns, the space allocated to the variable is reclaimed.

    To fix these you can either dynamically allocate space for the character array or declare it as static so that the lifetime of the variable becomes the entire program.

提交回复
热议问题