title: double to const char * by function
body: <pre><code>R=10;
  LPCSTR cs;
  string s;
  stringstream ss;
  ss&lt;&lt;R;
  s = ss.str();
  cout &lt;&lt; cs &lt;&lt;endl;
  </code></pre>
  
  <p>Will give me the console output 10, like it should be. </p>
  
  <p>Now I wanted to put this into a function:</p>
  
  <pre><code>const char * doubleToLPSTR(double x){
  string s;
  stringstream ss;
  ss &lt;&lt; x;
  s = ss.str();
  return s.c_str();
  
  }
  </code></pre>
  
  <p>But </p>
  
  <pre><code>R = 10;
  LPCSTR cs;
  string s;
  cs = doubleToLPSTR(R);
  cout &lt;&lt; cs &lt;&lt; endl;
  </code></pre>
  
  <p>Returns does not work.... Why???</p>
  
  <p>Thank you for your help, like this? </p>
  
  <pre><code>const char * doubleToLPSTR(double x){
  
  const int size = 20;
  char *cs = new char[size];
  
  string s;
  stringstream ss;
  ss &lt;&lt; x;
  s = ss.str();
  const char * tempAr = s.c_str();
  
  
  for (int i = 0; i &lt; size; i++){
  
      cs[i] = tempAr[i];
  
  }
  
  return cs;
  }
  </code></pre>