jeudi 9 septembre 2021

max function in c++ is not giving desired output for different length strings in c++

When I am trying to find maximum of two strings then it is giving me correct answer in 1st case( when passing string variables) but giving error in 2nd case(when passing direct strings).

#include<bits/stdc++.h>
using namespace std;
int main()
{
    // Case 1
    string str1 = "abc", str2 = "abcd";
    cout << max(str1, str2) << endl;

    //Case 2
    cout << max("abc", "abcd") << endl;
}

Aucun commentaire:

Enregistrer un commentaire