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

C++-এ রিলেশনাল অপারেটর (Relational Operators) দিয়ে স্ট্রিং অবজেক্ট তুলনা


এখানে আমরা দেখব C++-এ দুটি স্ট্রিং কীভাবে তুলনা করা যায়। C++-এ string ক্লাস আছে। সেটিতে compare() ফাংশন আছে। কিন্তু এখানে আমরা কন্ডিশনাল অপারেটর যেমন ==, !=, <, >, <=, >= ব্যবহার করব। এই অপারেটরগুলো স্ট্রিংয়ের ক্যারেক্টার একে একে চেক করে। ভালো বুঝতে কোডটি দেখুন।

উদাহরণ

#include<iostream> using namespace std; void compareStrings(string s1, string s2) {    if (s1 != s2)       cout << s1 << " is not equal to "<< s2 << endl;    else if(s1 == s2)       cout << "Strings are equal";    if (s1 > s2)       cout << s1 << " is greater than "<< s2 << endl;    else if(s1 < s2)       cout << s2 << " is greater than "<< s1 << endl; } int main() {    string s1("hello");    string s2("helLo");    compareStrings(s1, s2); }

আউটপুট

hello is not equal to helLo hello is greater than helLo

  1. C++ দিয়ে ইনপুট স্ট্রিংএ সর্বাধিকবার থাকা ক্যারেক্টার বের করা

  2. স্ট্রিং থেকে একটি নির্দিষ্ট শব্দ বাদ দেওয়া C++-এ

  3. C++ দিয়ে একটি স্ট্রিংয়ের সাবস্ট্রিং-এর সংখ্যা বের করা

  4. PHP অবজেক্ট তুলনা