#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
std::vector<std::string> str;
str.push_back("Vector");
str.push_back("of");
str.push_back("four");
str.push_back("words");
int chars = accumulate(str.begin(), str.end(), 0, [](int sum, const string& elem) {return sum + elem.size();});
std::cout << "Number of characters: " << chars; // 17 characters
// Are there any STL methods that allows me to find 'chars'
// without needing to write multiple for loops?
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKHZvaWQpCnsKICBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4gc3RyOwogIHN0ci5wdXNoX2JhY2soIlZlY3RvciIpOwogIHN0ci5wdXNoX2JhY2soIm9mIik7CiAgc3RyLnB1c2hfYmFjaygiZm91ciIpOwogIHN0ci5wdXNoX2JhY2soIndvcmRzIik7CgogIGludCBjaGFycyA9IGFjY3VtdWxhdGUoc3RyLmJlZ2luKCksIHN0ci5lbmQoKSwgMCwgW10oaW50IHN1bSwgY29uc3Qgc3RyaW5nJiBlbGVtKSB7cmV0dXJuIHN1bSArIGVsZW0uc2l6ZSgpO30pOwoKICBzdGQ6OmNvdXQgPDwgIk51bWJlciBvZiBjaGFyYWN0ZXJzOiAiIDw8IGNoYXJzOyAvLyAxNyBjaGFyYWN0ZXJzCgogIC8vIEFyZSB0aGVyZSBhbnkgU1RMIG1ldGhvZHMgdGhhdCBhbGxvd3MgbWUgdG8gZmluZCAnY2hhcnMnCiAgLy8gd2l0aG91dCBuZWVkaW5nIHRvIHdyaXRlIG11bHRpcGxlIGZvciBsb29wcz8KCn0=