title: C++ KMP algorithm printing output in main
body: <p>I got interested with text algorithms, I did find some ready example of C++ implementation of Knuth-Morris-Pratt algorithm which unfortunately does not include any working main() function. 
  I'm total newbie, hence it's hard for me to write any main function which will allow me to show the output of the code written below: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  vector&lt;int&gt; KMP(string S, string K)
  {
      vector&lt;int&gt; T(K.size() + 1, -1);
      vector&lt;int&gt; matches;
  
      if(K.size() == 0)
      {
          matches.push_back(0);
          return matches;
      }
  for(int i = 1; i &lt;= K.size(); i++)
  {
      int pos = T[i - 1];
      while(pos != -1 &amp;&amp; K[pos] != K[i - 1]) pos = T[pos];
      T[i] = pos + 1;
  }
  
  int sp = 0;
  int kp = 0;
  while(sp &lt; S.size())
  {
      while(kp != -1 &amp;&amp; (kp == K.size() || K[kp] != S[sp])) kp = T[kp];
      kp++;
      sp++;
      if(kp == K.size()) matches.push_back(sp - K.size());
  }
  
  return matches;
  }
  </code></pre>
  
  <p>As I understand, this function uses vector type to store all positions which match text with given pattern. -> vector 
  it returns vector type and I would like to print the results. </p>
  
  <p>I'm supposed to take two inputs from user string S and string K, to be able to use KMP function which uses S&amp;K strings as its arguments. </p>
  
  <p>Than I guess it would be useful to somehow print out the results of function (what this function KMP returns), but as it turned out simple cout command didn't do the trick. </p>
  
  <p>Should I use some kind of an iterator to display results returned by KMP function or what ? 
  Forgive me my novice level, but I can't figure it out all by myself. </p>
  
  <pre><code>int main()
  {
    string A,B; 
    cout &lt;&lt; "Input the text&amp;pattern in the following order: text first, pattern second";
  
    cin &gt;&gt; A; 
    cin &gt;&gt; B; 
  
    KMP(A,B); // initialize function with given strings  ?
  
    //using iterator to display the results; 
  
   for(vector&lt;int&gt;::iterator it = matches.begin(); it != matches.end(); it++) 
   {
      cout &lt;&lt; *it &lt;&lt; endl; 
   }
  
   return 0; 
   }
  </code></pre>