title: Comparing to a hardcoded string with quotes in C++
body: <p>I'm writing a c++ function to generate XML using TinyXML. I'd like to verify that a (relatively small) tree produced by my function gets turned into a string identical to a reference string.</p>
  
  <pre><code>// intended XML:
  &lt;element type="correct" /&gt;
  </code></pre>
  
  <p>It seems like the easiest way to do this comparison is to hardcode the reference string into the code:</p>
  
  <pre><code>//assignment
  std::string intended = "&lt;element type=\"correct\" /&gt;";
  </code></pre>
  
  <p>However, the backslashes to escape the quotes prevent the comparison from succeeding.</p>
  
  <pre><code>#include &lt;tinyxml.h&gt;
  #include &lt;string.h&gt;
  TiXmlElement test = TiXmlElement("element");
  test.SetAttribute("type", "correct");
  TiXmlPrinter printer;
  test.Accept(&amp;printer);
  ASSERT_EQ(intended, printer.CStr()); // gtests macro
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Value of: printer.CStr()
  Actual: "&lt;element type="correct" /&gt;"
  Expected: intended
  Which is: "&lt;element type=\"correct\" /&gt;"
  </code></pre>