কম্পিউটার টিউটোরিয়াল

C++ STL-এ set::find() ফাংশন

find() ফাংশন

set::find(k) কী k সেটে আছে কিনা চেক করে। পাওয়া গেলে সেই এলিমেন্টের ইটেরেটর রিটার্ন করে, না পেলে end() রিটার্ন করে।

উদাহরণ কোড

#include <iostream>
#include <set>
using namespace std;

int main() {
    set<int> s = {1, 2, 4, 6, 7, 9, 10};
    auto it = s.find(6);
    if (it != s.end()) {
        cout << "Found: " << *it << endl;
        cout << "Elements from 6 onwards: ";
        for (; it != s.end(); ++it) cout << *it << " ";
    } else {
        cout << "Not found";
    }
    return 0;
}

আউটপুট

Found: 6
Elements from 6 onwards: 6 7 9 10

বनाम lower_bound: find শুধু এক্সएक্ট ম্যাচ খুঁজে; lower_bound নেইলে পরবর্তী বড়টি দেয়।

  1. C++ STL-এ negate ফাংশন: মানগুলোর সাইন পরিবর্তন

  2. C++ STL-এ atan2() ফাংশন

  3. C++ STL-এ acos() ফাংশন

  4. C++ STL-এ asinh() ফাংশন