How do you reverse a string in place in C or C++?

前端 未结 30 1933
长发绾君心
长发绾君心 2020-11-22 00:37

How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string?

30条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 01:40

    I think there is another way to reverse the string. get the input from user and reverse it.

    void Rev() {
        char ch;
        cin.get(ch);
        if(ch != '\n') {
            Rev();
            cout.put(ch);
        }
    }
    

提交回复
热议问题