title: Output whole sentence when reversing words in string c++
body: <p>Have to create our own function that receives a sentence/sentences from an input file. It then should reverse the letters of each word individually and leaves all other (non-alphabetic) characters in the plaintext unchanged i.e &quot;The cat sat on the mat!&quot; will become
  &quot;ehT tac tas no eht tam!&quot;.
  So I think I have found a way to reverse words individually but don't know how to find a way to output everything in one sentence. I feel like I would need to somehow use arrays or vectors to help store each word, and then output all the words  together at the end, but I have not been successful.
  I also want to find a way for it to know when to stop and to output the blank spaces between words.</p>
  <p>Here is my code so far:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std; 
  
  void reverse(string input); 
  
  int main(){
      ifstream inData; 
      ofstream outData; 
  
      string input; 
  
      inData.open(&quot;input.txt&quot;); 
      outData.open(&quot;output.txt&quot;); 
  
      while(getline(inData, input)){
          // cout &lt;&lt; input; 
          outData &lt;&lt; input; 
      }
  
     
      reverse(input);
  
      inData.close(); 
      outData.close(); 
      return 0; 
  }
  
  void reverse(string input){
    
      int counter =0;
      while(counter != 14){
      int idx = input.find(&quot; &quot;);
      cout &lt;&lt; idx &lt;&lt; endl;
  
      string word = input.substr(0, idx);
      cout &lt;&lt; word &lt;&lt; endl;
      string x;
  
      for (int i = idx-1; i &gt;= 0; i--)
      {
          x= word.at(i);
          cout &lt;&lt; x; 
      }
  
      cout &lt;&lt; endl;
      input.erase(0,idx+1);
  
      cout &lt;&lt; input &lt;&lt; endl;
  
      cout &lt;&lt; endl &lt;&lt; &quot;new&quot; &lt;&lt; endl;
      
      counter++; 
      }
  } 
  </code></pre>