c++ for_each() and object functions

前端 未结 10 817
盖世英雄少女心
盖世英雄少女心 2021-01-14 05:31

I have an assignment that is the following:

For a given integer array, find the sum of its elements and print out the final result, but to get the sum, you need to e

10条回答
  •  -上瘾入骨i
    2021-01-14 05:43

    vector v(array[0], array[10]);
    

    This doesn't do what you want. array[0] is the first value (1). array[10] is in invalid access past the end of your array. To pass pointers to the vector constructor, you want:

    vector v(array, array+10);
    

提交回复
热议问题