Vector container / list

I need to add each item from my function into a list, array or a vector container. But i'm unsure which one or how to do so.. i need to then later access that list and cycle through one by one.

Here is the code i'm using, any help is appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
template <class InIter1, class InIter2, class OutIter>
void find_all(unsigned char *base, InIter1 buf_start, InIter1 buf_end, InIter2 pat_start, InIter2 pat_end, OutIter res) {

    for (InIter1 pos = buf_start;
        buf_end!=(pos=std::search(pos, buf_end, pat_start, pat_end));
        ++pos)
    {
        std::cout << "";setcolor(0);std::cout<<"    ";setcolor(160);
        *res++ = base+(pos-buf_start);

    }
}
So, the first thing to do is to fix your return type. For simplicity sake, I suggest returning an std::vector as a copy. Yes it's expensive but it's also easy. Another easy alternative is to accept a pointer to an std::vector as an argument. That would be computationally cheaper while still being simple to use and easy to read. Why are we using a template for iterators? Pretty much all of the standard existing containers have those built in already.
Topic archived. No new replies allowed.