Answers for "Write a function called max_size that takes a vector of strings as an input and returns the string with the maximum length."

C++
0

Write a function called max_size that takes a vector of strings as an input and returns the string with the maximum length.

// ALWAYS USE PASS BY REFERENCE WITH STRINGS AND VECTORS.

string max_size (const vector <string> & v)

{

    string result;

     for (int i = 0;  i < v.size(); i++)

     {

           if ( v[i].length() > result.length() )

           {

              result = v[i];

            } 

    }

  return result;

}
Posted by: Guest on April-07-2021

Code answers related to "Write a function called max_size that takes a vector of strings as an input and returns the string with the maximum length."

Browse Popular Code Answers by Language