我创建了一个程序来反转一个句子:
#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)
我不知道我做错了什么。帮助?