You are viewing a single comment's thread. Return to all comments →
Try to do this task using C++! In C++ this is a single line of code and is more generic!
cout << accumulate(istream_iterator<int>(cin), istream_iterator<int>(), 0);
This can be read as "sum all elements from standard input starting from 0 as start value".
The power of C++ are containers, algorithm and iterator.
containers
algorithm
iterator
Input and Output
You are viewing a single comment's thread. Return to all comments →
Try to do this task using C++! In C++ this is a single line of code and is more generic!
cout << accumulate(istream_iterator<int>(cin), istream_iterator<int>(), 0);
This can be read as "sum all elements from standard input starting from 0 as start value".
The power of C++ are
containers
,algorithm
anditerator
.