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