So, although it is trivial to find the number of characters that are inside the std :: string vector, I was wondering if there is a way to use STL to do all the work for you, and not for two loops, skip one through the vector and the other through the string in each vector index.
I tried using other STL functions (for example, trying to use std :: for_each in several unique ways), but all my attempts did not lead to success.
int main(void) { int chars = 0; std::vector<std::string> str; str.push_back("Vector"); str.push_back("of"); str.push_back("four"); str.push_back("words"); for(int i = 0; i < str.size(); ++i) for(int j = 0; j < str[i].size(); ++j) ++chars; std::cout << "Number of characters: " << chars;
source share