Print string without escaping characters
<p>This code:</p>

<pre><code>void Controller::write(const std::string&amp; str) {
    std::cout &lt;&lt; "Writing: [" &lt;&lt; str &lt;&lt; "] to board." &lt;&lt; std::endl; 
    s.write(str);
</code></pre>

<p>takes a <code>string</code> and pushes it over a serial link to a microcontroller. (This works fine). However, when I try to push a like this: <code>write("ats203?\r")</code>, the console output looks like this: </p>

<pre><code>] to board.ts203?
</code></pre>

<p>So the <code>Writing: [a</code> gets overwritten by the <code>] to board.</code> after <code>std::cout</code> encounters the <code>\r</code> in the string. </p>

<p>How can I print the string as a bunch of characters rather than mangling console output when an escape character is encountered?  </p>

<p>EDIT: To clarify. </p>

<p>I <em>want</em> my string to be <code>ats203?\r</code>. This is because the microcontroller is controlled using a slightly modified version of an <a href="http://en.wikipedia.org/wiki/Motorola_phone_AT_commands" rel="nofollow">AT command</a>, and <em>doesn't accept the command until it reads a <code>\r</code></em>. When the string is pushed to the microcontroller, it reads the <code>\r</code> as a carriage return, and acts on things it read prior to the <code>\r</code>. </p>

<p>What I want is to display the string that I've constructed. There is a bunch of other commands elsewhere that get created depending on flags that are set at runtime. So I end up with strings that look something like <code>ate1\ratv0\rat+OSA=7\rat+OSX=255\r</code>. </p>

<p>I would like to see what I've constructed and what I'm pushing. I can't do this, because <code>std::cout</code> reads the carriage return, acts on it, and mangles my console output. </p>

<p>EDIT: Clarification, again: 
I want <code>std::cout &lt;&lt; "Writing: [" &lt;&lt; str &lt;&lt; "] to board." &lt;&lt; std::endl;</code> to produce (when <code>str</code> is <code>ats203?\r</code>):</p>

<pre><code>Writing: [ats203?\r] to board. 
</code></pre>
