title: Reverse order of words in a string
body: <p>I am working a problem to reverse the order of words in a string. For example, if you have str1 = "the sky is blue" then the solution should be "blue is sky the".</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class Solution 
  {
      public:
          list&lt;string&gt; words;
  
          void createList(string s)
          {
              istringstream iss(s);
              string token;
  
              while(getline(iss, token, ' '))
              {
                  words.push_back(token);
              }
          }
  
          string reverseWords(string s) 
          {
              list&lt;string&gt;::iterator iter = words.begin();
              string newString = "";
  
              createList(s);
              newString.append(*iter);
              for (iter = (iter+1); iter != words.end(); iter++)
              {
                  newString.append(" ");
                  newString.append(*iter);
              }
  
              return newString;
          }
  };
  </code></pre>
  
  <p>My question is.... 
  Am I using the list iterator correctly? I got a compiler error that said "Line 25: no match for ‘operator+’ " referring to the for loop in reverseWords().</p>