Unexpected Run time error with simple code
<p>Can anybody please tell me why iam getting an unexpected run-time error for the code given below. It works for two times iteration but not for more than that.</p>

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

using namespace std;
void print(string hmm)
{
         ofstream ko(hmm.c_str(),ios::trunc);
         ko&lt;&lt;"chacho";
         ko.close();
}

int main(){
for(int i=0;i&lt;5;i++)
{
        char *chat=new char;
        sprintf(chat,"%d%s",i,"_num.txt");
        string rat=chat;

        print(rat);
}

system("pause");
return 0;
}
</code></pre>
