please help me...

Hi
how I can having sum in loop function,please give me example if you can!!.
1
2
3
4
5
std::vector<int> cont {4, 2, 6, 1, 3};
int sum = 0;
for(const auto v: cont)
    sum += v;
std::cout << sum;
16
I would suggest looking into "std::accumulate()": http://www.cplusplus.com/reference/numeric/accumulate/

To help you any more then that though we would need to see some of your code.

EDIT: Bah! Ninja'd! I thought about suggesting a range based for loop, but this one won the coin toss.
Last edited on
Topic archived. No new replies allowed.