Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m just not quite there yet, have tried different ways that I know and it does

ID: 3848290 • Letter: I

Question

I'm just not quite there yet, have tried different ways that I know and it doesn't work. It's sort of hard without using loops.

Without using any loops or recursion, write a function getLengths that, given a vector of std::strings, uses std:: function templates to produce a list of integers containing the lengths of each string in the vector.

For example, given a vector v0 with the strings ["abc", "", "defg", "h"], the call getLengths(v0) should return a list with the integers [3,0,4,1].

Your function should match the declaration:

std::list<size_t> getLengths (const std::vector<std::string>& v0);

Explanation / Answer

Please find my code.

std::list<size_t> getLengths (const std::vector<std::string>& v0) {

   std::list<size_t> myList;
  
   // getting iterator
   vector<std::string>::iterator i = my_vector.begin();

   //iterator using iterator
   while (i != my_vector.end())
   {
       myList.push_back((*it).lenght())
   ++i;
   }

   return myList;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote