title: C++ - Adding Spaces to String
body: <p>Hey so I am trying to write a simple program that adds spaces to a given string that has none in C++ here is the code I have written:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  string AddSpaceToString (string input)
  {
      const int arrLength = 5;
      int lastFind = 0;
      string output;
      string dictionary[arrLength] = {"hello", "hey", "whats", "up", "man"};
  
      for (int i = 0; i &lt; input.length(); i++)
      {
          for (int j = 0; j &lt; arrLength; j++)
          {
              if(dictionary[j] == input.substr(lastFind, i))
              {
                  lastFind = i;
                  output += dictionary[j] + " ";
              }
          }
      }
  
      return output;
  }
  
  int main ()
  {
      cout &lt;&lt; AddSpaceToString("heywhatshelloman") &lt;&lt; endl;
  
      return 0;
  } 
  </code></pre>
  
  <p>For some reason the output only gives <code>hey whats</code> and then stops.  What is going on I can't seem to make this very simple code work. </p>