如何使用 std::reverse 反转 std::string (C++)

reverse_string_cpp.cpp
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char** argv) {
    std::string s = "My string";
    // 这会原地反转 s。
    std::reverse(std::begin(s), std::end(s));
    // 打印 "gnirts yM"
    cout << s << endl;
}

Check out similar posts by category: C/C++