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

前端 未结 30 2482
长发绾君心
长发绾君心 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:39

    Use the std::reverse method from STL:

    std::reverse(str.begin(), str.end());
    

    You will have to include the "algorithm" library, #include.

提交回复
热议问题