g++11 和 g++13 之间 std::begin、std::end 发生了什么变化

问题描述 投票:0回答:1

这可能是一个愚蠢的问题。但我注意到这一行没有在我的机器上编译,唯一的区别是安装的 g++ 版本。 我将版本更新回 11,它又开始工作了。我不认为这有什么问题。 我可以得到一些帮助吗?

char shipLetters[] = { 'A', 'B', 'S', 'C', 'D' };

这适用于 g++11,但不适用于 g++13

char seletion;
cin >> selection;
index = std::find(begin(shipLetters), end(shipLetters), selection);

enter image description hereenter image description here

添加了可运行的示例。

#include <iostream>

using namespace std;
int main() {
  char shipLetters[] = { 'A', 'B', 'S', 'C', 'D' };
  char selection;
  cin >> selection;
  char *index = std::find(begin(shipLetters), end(shipLetters), selection);
  cout << index << endl;
  return 0;
}
g++ std
1个回答
0
投票

看起来我只需要明确地包含算法即可。我不确定为什么运行 g++11 时没有出错,但它现在可以工作了。

#include <iostream>
#include <algorithm>

using namespace std;
int main() {
  char shipLetters[] = { 'A', 'B', 'S', 'C', 'D' };
  char selection;
  cin >> selection;
  char *index = std::find(begin(shipLetters), end(shipLetters), selection);
  cout << index << endl;
  return 0;
}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.