Clause 26.7.2 / 1 of the C ++ 11 standard states:
template <class InputIterator, class T> T accumulate(InputIterator first, InputIterator last, T init);
[...]
1 Effects: calculates its result by initializing the accumulator acc with the initial value init, and then changing it with acc = acc + *i [...] for each iterator i in the range [first,last) in order.
[...]
String literals are of type const char[] , decaying to const char* when you pass them to functions. Therefore, the initializer that you pass to accumulate() will be const char* , and T will be const char* .
This means that acc from the above expression will be const char* , and *i will be string . This means that the following will not compile:
acc = acc + *i;
Because acc + *i gives std::string , and on the left side of the job you have const char* .
Like others, you must do:
string num = accumulate(v.begin(),v.end(),string());
In addition, you do not need to do:
v.push_back(string("a"));
When inserting strings into a vector. It's enough:
v.push_back("a");
An std::string will be implicitly constructed from the string literal "a" .