fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main() {
  8. std::vector<std::string> foo;
  9. foo.push_back("A");
  10. foo.push_back("B");
  11. std::string::size_type total = 0;
  12. std::accumulate(foo.begin(), foo.end(), total,
  13. [](std::string::size_type i, std::string const& s) { return i + s.size(); });
  14. cout << total << endl;
  15. std::string result;
  16. result.reserve(total);
  17. std::for_each(foo.begin(), foo.end(),
  18. [&](std::string const& s) { result += s; });
  19. cout << result << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
0
AB