Schbabako Schbabako - 1 year ago 88
C++ Question

Matrix input and interpretation of the Input

i have a short question about an initialization that I don't fully understand.
About the code: I'm looking for pairs and my vector "vector temp" saves the places where my loop found a pair. after my Temp is filled with some values I check it to look where the pairs were found. I made 2 for loops to loop through the vector. Outer loop i and inner loop j. Temp stores the j value where a pair is found.
Now about my question, this is the code

`bool repeat = 1;
vector<double>::iterator rep_check;
rep_check = find(repeat_check.begin(), repeat_check.end(), d_in[i]);
if( rep_check == repeat_check.end() ) repeat = 0;
if(!repeat) out.push_back(temp);
else out.push_back(vector<int> (1,temp[0]));`

This part is still in the i loop!!!!!
I dont understand the last part: 'vector (1,temp[0])'. this gets pushed into my output matrix (2x2 Matrix), but i dont understand the syntax here. How do i have to interpret this last part?

Answer Source

What you are doing here is pushing back a vector<int> in a container (I guess it is a vector) named out. The constructor call is vector<int> (1,temp[0]) and it says that you want to construct a vector<int> with size 1 and the vector elements (in this case only one) are initialized with the value of temp[0].

The prototype of this vector constructor looks like:

explicit vector (size_type n, const value_type& val = value_type(),
                 const allocator_type& alloc = allocator_type());

and the description is: Fill constructor: Constructs a container with n elements. Each element is a copy of val.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download