笔记:STL中的函数:accumulate(求和)

来源:互联网 发布:淘宝客注册要钱吗 编辑:程序博客网 时间:2024/05/21 10:11
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
        vector<string>  vecs = {"hello", " ", "world!"};
        vector<int>     veci = {1, 3, 6};

        string s = accumulate(vecs.begin(), vecs.end(), string("test accumulate: "));
        int i = accumulate(veci.begin(), veci.end(), 11);

        cout << s << endl;
        cout << i << endl;


        return 0;

}

编译:

g++ -std=c++11 test_accumulate.cpp

运行结果:

test accumulate: hello world!
21

0 0
原创粉丝点击