C++ string - how to swap a string with two characters?
<p>Given a C++ string str("ab"), how do I swap the content of str so that it becomes "ba".
Here is my code:</p>

<pre><code>    string tmpStr("ab");

    const char&amp; tmpChar = tmpStr[0];
    tmpStr[0] = tmpStr[1];
    tmpStr[1] = tmpChar;
</code></pre>

<p>Is there a better way?</p>

<p>Thank you</p>
