ZBLOG

'class std::vector' has no member named 'find' | 6596 | } else if (allStatus.find(allStatus.begin(), allStatus.end(), "Waring")

你的代码中出现了错误。std::vector 类型没有名为 find 的成员函数,因此会报错提示该类型没有名为 ‘find’ 的成员。

如果你想在一个字符串向量中查找特定的字符串元素,可以使用标准库算法中的 std::find() 函数。它可以帮助你在容器中查找指定值,并返回迭代器指向该值所在位置。

示例代码如下:

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<std::string> allStatus = {"Warning", "Error", "Info"};

    auto it = std::find(allStatus.begin(), allStatus.end(), "Warning");
    if (it != allStatus.end()) {
        std::cout << "Found 'Warning' at index: " << std::distance(allStatus.begin(), it) << std::endl;
    } else {
        std::cout << "'Warning' not found." << std::endl;
    }

    return 0;
}

以上代码将在 allStatus 向量中查找字符串 “Warning”,并输出其索引位置(如果存在)。请注意确保包含了 <algorithm> 头文件以使用 std::find() 函数。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=11859

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?