C++ 标准库 std::npos 表示 size_t 的最大值


参见:https://en.cppreference.com/w/cpp/algorithm/find

 

std::npos 表示 size_t 的最大值,常用于对查找结果成功与否的判断。

#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
 
int main()
{
    int n1 = 3;
    int n2 = 5;
 
    std::vector<int> v{0, 1, 2, 3, 4};
 
    auto result1 = std::find(std::begin(v), std::end(v), n1);
 
    if (result1 == std::npos) {
        std::cout << "no found " << n1 << '\n';
    }

    return 0  
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM