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

前端 未结 7 1554
清歌不尽
清歌不尽 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 21:56

    See sharptooth for explanation.

    Try this instead:

    #include 
    
    void main()
    {
        char someString[27];
        std::strcpy( someString, "Hi there, I'm bad at this." );
        strReverse( someString );
    }
    

    Better yet, forget about char * and use instead. This is C++, not C, after all.

提交回复
热议问题