Allocating C-style string on the Heap
<p>guys, I need a little technical help.
I'm working in C++, don't have much experience working in it but know the language somewhat. I need to use a C-style string (char array) but I need to allocate it on the heap.</p>

<p>If you look at this very simple piece of code:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

char* getText()
{
    return "Hello";
}

int main()
{
    char* text;
    text = getText();
    cout &lt;&lt; text;
    //delete text; // Calling delete results in an error
}
</code></pre>

<p>Now, I'm assuming that the "Hello" string is allocated on the stack, within getText(), which means the pointer will be "floating" as soon as getText returns, am I right?</p>

<p>If I'm right, then what's the best way to put "Hello" on the heap so I can use that string outside of getText and call delete on the pointer if I need to?</p>
