title: C++ RapidJSON Writer and String Buffer outputting unknown characters
body: <p>I have a class representing an object in 3-space, and a to_json method which outputs a const char* to convert the object into a JSON for writing back to a document based database.  However, the to_json method is outputting unknown characters rather than a JSON Message</p>
  
  <pre><code>const char* Obj3::to_json() const
  {
      logging-&gt;info("Obj3:To JSON Called");
      //Initialize the string buffer and writer
      StringBuffer s;
      Writer&lt;StringBuffer&gt; writer(s);
  
      //Start writing the object
      //Syntax taken directly from
      //simplewriter.cpp in rapidjson examples
  
      writer.StartObject();
  
      writer.Key("key");
      std::string key = get_key();
      writer.String( key.c_str(), (SizeType)key.length() );
  
      writer.Key("owner");
          std::string owner_dev = get_owner();
          writer.String( owner_dev.c_str(), (SizeType)owner_dev.length() );
  
      writer.Key("name");
      std::string name = get_name();
      writer.String( name.c_str(), (SizeType)name.length() );
  
      writer.Key("type");
      std::string type = get_type();
      writer.String( type.c_str(), (SizeType)type.length() );
  
      writer.Key("subtype");
      std::string subtype = get_subtype();
      writer.String( subtype.c_str(), (SizeType)subtype.length() );
  
      int i;
      int j;
  
      writer.Key("location");
      writer.StartArray();
      for (i=0; i&lt;3; i++) {
          writer.Double( static_cast&lt;double&gt;(get_loc(i)) );
      }
      writer.EndArray();
  
      writer.Key("transform");
      writer.StartArray();
  
          for (i=0; i&lt;4; i++) {
          writer.StartArray();
          for (j=0; j&lt;4; j++) {
                  writer.Double( static_cast&lt;double&gt;(transform_matrix(i, j) ));
          }
          writer.EndArray();
          }
  
          writer.EndArray();
  
      writer.Key("scenes");
      writer.StartArray();
          for (i=0; i&lt;num_scenes(); i++) {
          std::string sc = get_scene(i);
                  writer.String( sc.c_str(), (SizeType)sc.length() );
          }
          writer.EndArray();
  
      writer.Key("locked");
      writer.Bool(is_locked);
  
      writer.EndObject();
  
      //The Stringbuffer now contains a json message
      //of the object
      if (writer.IsComplete()) {
          logging-&gt;debug("Valid JSON Encountered");
          try {
              return s.GetString();
          }
          catch (std::exception&amp; e) {
              logging-&gt;error("Exception Encountered parsing JSON");
              logging-&gt;error(e.what());
          }
      }
      else {
          return "";
      }
  
  }
  </code></pre>
  
  <p>The logs show the below output:</p>
  
  <pre><code>2016-04-30 13:15:54,151 [INFO] Obj3:To JSON Called
  2016-04-30 13:15:54,151 [DEBUG] Valid JSON Encountered
  ��
  </code></pre>
  
  <p>I've closed all of the arrays and the root object, and am checking for completeness per the API, however the output is not readable via std::cout or log4cpp.</p>
  
  <p>--Edit--</p>
  
  <p>Per the below response, I updated the return type to std::string and the return statement to the below:</p>
  
  <pre><code>//The Stringbuffer now contains a json message
  //of the object
  if (writer.IsComplete()) {
      logging-&gt;debug("Valid JSON Encountered");
      try {
          const char* ret_val = s.GetString();
          std::string ret_string (ret_val);
          return ret_string;
      }
      catch (std::exception&amp; e) {
          logging-&gt;error("Exception Encountered parsing JSON");
          logging-&gt;error(e.what());
      }
  }
  else {
      return "";
  }
  </code></pre>
  
  <p>Which results in a segmentation fault.</p>
  
  <p>The method is being called in the test as below:</p>
  
  <p><code>std::cout &lt;&lt; obj.to_json() &lt;&lt; std::endl;</code></p>