C++ - copying from const char* to string
<p>Is there a way to copy string from <code>const char*</code> to <code>string</code> in C++? I'm trying to do something like this:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string.h&gt;

using namespace std;

int main(){

    string s1;
    const char* pStr = "Sample Text";

    for(int i = 0; i &lt; strlen(pStr); i++)
        s1[i] = pStr[i];

    cout&lt;&lt;s1&lt;&lt;endl;

    return 0;
}
</code></pre>

<p>In my case <code>s1</code> turns out to be empty.</p>