title: Reverse words in a sentence in c++ using stack
body: <p><strong>Input</strong></p>
  
  <p>"the sky is blue"</p>
  
  <p><strong>Expected Output</strong></p>
  
  <p>"blue is sky the"</p>
  
  <p><strong>My Output</strong></p>
  
  <p>"blue is sky "</p>
  
  <p><strong>I am unable to point out the error in the code.</strong></p>
  
  <p>Here is the code :</p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main() {
      string s = "the sky is blue";
      reverse(s.begin(),s.end());
      stack&lt;char&gt; t;
      for(int i = 0;i &lt; s.length();i++){
          if(s[i] != ' '){
              t.push(s[i]);
          }
          else{
              while(!t.empty()){
                  cout &lt;&lt; t.top();
                  t.pop();
              }
              cout &lt;&lt; " ";
          }
      }
      return 0;
  }
  </code></pre>