Your code looks so good, i'm quite impressive of you were learning c++ few days ago. i'm sure you will get a decent code-review but here my humble attempt.
It always preferred to pass the std::string by const reference if you don't modify it. also, std::vector is preferred over std::list. here link for more details
In your read function. It redirects all input into this container until EOF is received. However, the used container might need to reallocate memory too often, or you will end with a std::bad_alloc exception when your system gets out of memory. In order to solve these problems, you could reserve a fixed amount N of elements and process these amount of elements. here an alternative example to your read function by using std::copy_n and std::istream_iterator like so,
words.reserve(N);
std::copy_n(std::istream_iterator<std::string>(std::cin),
N,
std::back_inserter(words));
In your evaluate function, it is fine but not efficient doe to the call of std::string constructor in every iteration along with deleting un-palindrome elements. it is better to create another container for palindrome elements and check the main container elements if it has palindrome element. possible implementation:
bool is_palindrome(const std::string& str)
{
if (str.empty())
return false;
using str_sz = std::string::size_type;
for (str_sz i = 0, j = str.length() -1; i < j ; ++i, --j)
{
if (str[i] != str[j])
return false;
}
return true;
}
Lastly, for longest string, you may take advantage of STL by using std::max_element which is return iterator.
put all to gather:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
bool is_palindrome(const std::string& str)
{
if (str.empty())
return false;
using str_sz = std::string::size_type;
for (str_sz i = 0, j = str.length() -1; i < j ; ++i, --j)
{
if (str[i] != str[j])
return false;
}
return true;
}
int main()
{
const std::size_t N = 3;
std::vector<std::string> words;
words.reserve(N);
std::cout << "Please enter some words." << std::endl;
std::copy_n(std::istream_iterator<std::string>(std::cin),
N,
std::back_inserter(words));
std::vector<std::string> palindromes;
for (const auto& word : words)
{
if(is_palindrome(word))
palindromes.emplace_back(word);
}
if(palindromes.empty())
{
std::cout << "No palindromes were given" << std::endl;
}
else
{
auto longest = std::max_element(palindromes.begin(), palindromes.end());
for (const auto& word : palindromes) std::cout << word << std::endl;
std::cout << "longest: " << *longest << std::endl;
}
}