title: Returning empty string from C++ through JNI to Java
body: <p>I'm making a X-platform library and I'm trying to export it to Java.</p>
  
  <p>There's a function which returns me a string:</p>
  
  <p><strong>C++ code</strong></p>
  
  <pre><code>string results = "";
  
  
  for (vector&lt;int&gt;::size_type i = 0; i &lt; resultsDouble.size(); i++) {
      for (it_type3 it = distances.begin(); it != distances.end(); ++it) {
          String key = it-&gt;first;
          double value = distances.at(key);
  
          if (value == resultsDouble.at(i)) {
              typesString.push_back(key);
              results = results + " " + key;
          }
      }
  }
  
  char const* resultsChar = results.c_str();
  
  return resultsChar;
  </code></pre>
  
  <p>when printing it on Java, even on the JNI call it's empty.</p>
  
  <p>It is empty as well if I make <code>to_string(results).c_str();</code></p>
  
  <p>But I know that the string isn't empty because when I print <code>to_string(results.length()).c_str();</code> it shows me 435 .</p>
  
  <p>Why is it showing me an empty string?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>If I change my result to string, I get:</p>
  
  <blockquote>
    <p>Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1), thread 17339 (w.opencvtesting) </p>
  </blockquote>
  
  <p><strong>EDIT 2</strong>
  I'm trying to to this:</p>
  
  <pre><code>string getMyString(string JSON, long proof) {
      string result = "";
      return result;
  }
  </code></pre>
  
  <p>and what the log prints me is:</p>
  
  <blockquote>
    <p>Ж)¤</p>
  </blockquote>