In the code below I attempt to print the largest std::string
in a std::vector
using std::max_element
.
I expected the output of the code below to be:
Harmlessness
The actual output I got is:
This
The code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
vector <string> strlist;
strlist.push_back("This");
strlist.push_back("Harmless");
strlist.push_back("Harmlessness");
cout << *max_element(strlist.begin(), strlist.end());
return 0;
}
My question:
Can you explain why the code produced the actual output above and not the one I expected ?