title: Printing set using the copy function
body: <p>The problem I am having is that I need to print the resulting set from the union_set function using the copy function. (So I am not allowed to just put output as the last term of the set_union function). I cannot seem to get the copy function to work correctly for the lastAunionB pointer (i have to to a few more times as well). What I have currently is just my last attempt at an answer, although I tried many more things. What am I doing incorrectly with the copy function? Here is the code. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;set&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main()
  {
      int setA[5] = {2, 4, 5, 7, 8};
      int setB[7] = {1, 2, 3, 4, 5, 6, 7};
      int setC[5] = {2, 5, 8, 8, 15};
      int setD[6] = {1, 4, 4, 6, 7, 12};
  
      set&lt;int&gt; set2A(setA,setA+5);
      set&lt;int&gt; set2B(setB,setB+7);
      set&lt;int&gt; set2C(setC,setC+5);
      set&lt;int&gt; set2D(setD,setD+6);
  
  
      int AunionB[12];
      int AunionC[10];
      int BunionD[13];
      int AintersectB[12];
      int AintersectC[10];
  
      set&lt;int&gt; finalUnion;
      set&lt;int&gt; finalIntersection;
      set&lt;int&gt; final2Union;
      set&lt;int&gt; final2Intersection;
      set&lt;int&gt; final2Difference;
      ostream_iterator&lt; int &gt; output( cout, " " );
  
      int *lastAunionB;
      int *lastAunionC;
      int *lastBunionD;
      int *lastAintersectB;
      int *lastAintersectC;
  
      cout &lt;&lt; "setA = ";
      copy(set2A.begin(), set2A.end(), output);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "setB = ";
      copy(set2B.begin(), set2B.end(), output);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "setC = ";
      copy(set2C.begin(), set2C.end(), output);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "setD = ";
      copy(set2D.begin(), set2D.end(), output);
      cout &lt;&lt; endl;
  
      //here is where the problem lies
      cout &lt;&lt; "AunionB = ";
      lastAunionB = set_union(setA, setA+5, setB, setB+7, AunionB);
      copy(lastAunionB, lastAunionB, output);
      cout &lt;&lt; endl;
  
      /*
      cout &lt;&lt; "AunionC = ";
      set_union(setA, setA+5, setC, setC+5, AunionC);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "BunionD = ";
      set_union(setB, setB+7, setD, setD+6, BunionD);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "AintercectB = ";
      set_intersection(setA, setA+5, setB, setB+7, AintersectB);
      cout &lt;&lt; endl;
  
      cout &lt;&lt; "AintercectC = ";
      set_intersection(setA, setA+5, setC, setC+7, AintersectC);
      cout &lt;&lt; endl;
  
      */
  
      return 0;
  </code></pre>
  
  <p>}</p>