Memory access violation. What's wrong with this seemingly simple program?

前端 未结 7 1577
清歌不尽
清歌不尽 2021-01-20 21:50

This is a quick program I just wrote up to see if I even remembered how to start a c++ program from scratch. It\'s just reversing a string (in place), and looks generally c

7条回答
  •  一个人的身影
    2021-01-20 22:12

    The line

    char *someString = "Hi there, I'm bad at this.";
    

    makes someString point to a string literal, which cannot be modified. Instead of using a raw pointer, use a character array:

    char someString[] = "Hi there, I'm bad at this.";
    

提交回复
热议问题