我正在尝试运行此比较器:
if (std::find(movements->begin(), movements->end(), commandBuffer) != movements->end())
与:const std::string movements[8] = {"north", "south", "east", "west", "n", "s", "e", "w"};
其中commandBuffer
是std::string
。在MinGW32 9.2.0上,我得到以下信息:
error: no match for 'operator==' (operand types are 'const char' and 'const std::__cxx11::basic_string')
最佳答案
使用std::cbegin
和std::cend
,或将数组更改为std::array
:
std::array<const std::string, 8> movements = {"north", "south", "east", "west", "n", "s", "e", "w"};
const std::string commandBuffer = "north";
if (std::find(movements.begin(), movements.end(), commandBuffer) != movements.end())
std::cout << "Found!" << std::endl;
关于c++ - 使用std::find和std::string数组时出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64261856/