I have this example code that doesn't compile:
#include <iostream>
#include <vector>
using std::endl; using std::cin; using std::cout;
using std::vector;
int main()
{
vector<int> vi, seg;
vi.push_back(3);
vi.push_back(4);
vi.push_back(5);
vi.push_back(6);
vi.push_back(7);
vector<int>::const_iterator ci_start = vi.begin();
vector<int>::const_iterator ci_actual = vi.begin();
while (ci_actual != vi.end())
{
seg = vi(ci_start, ci_actual);
cout << "......" ;
for (const vector<int>::const_iterator ci = vi.begin();
ci != vi.end(); ++ci)
cout << *ci << " ";
cout << endl;
++ci_actual;
}
}
What I want is to pass increasing parts of vector vi
(that is going to take some million elements) to a function (not shown). These segments are considered from the begining of vi
up to where actual
is at the moment.
For this, I've declared seg
that was supposed to have part of vi.
Desired output would be:
3
3 4
3 4 5
3 4 5 6
3 4 5 6 7
Is seg
not supposed to hold a copy of elements of vi
denoted by iterators ci_start
and ci_actual
?
To pass the ever increasing part of vi
to the function I refered (absent), can I do it faster without copying the elements of vi
to another vector and just pass a reference to a segment of vi
?