小编Abi*_* T.的帖子

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

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

#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)

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

c++ reverse mingw g++ std

-2
推荐指数
1
解决办法
2865
查看次数

标签 统计

c++ ×1

g++ ×1

mingw ×1

reverse ×1

std ×1