错误:'reverse' 未在此范围内声明

Abi*_* T. -2 c++ reverse mingw g++ std

我创建了一个程序来反转一个句子:

#include <iostream>
#include <string>   

using namespace std;

int main()
{
    string sentence;
    string reversedSentence;
    int i2 = 0;

    cout << "Type in a sentence..." << endl;
    getline(cin, sentence);

    reversedSentence = sentence;
    reverse(reversedSentence.begin(), reversedSentence.end());

    cout << sentence << endl;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试用 MinGW G++ 编译它时,会发生这种情况:

SentenceReverser.cpp: In function 'int main()':
SentenceReverser.cpp:16:5: error: 'reverse' was not declared in this scope
   16 |     reverse(reversedSentence.begin(), reversedSentence.end());
      |     ^~~~~~~
Run Code Online (Sandbox Code Playgroud)

我不知道我做错了什么。帮助?

cdh*_*wie 12

std::reverse()algorithm头文件中定义。包括:

#include <algorithm>
Run Code Online (Sandbox Code Playgroud)

另外,避免using namespace std;.