A
alan
Hi all,
I have a problem on free allocated memory in C++.
Here is my testing program.
I use VS6.0 to compile it successfully.
But there "delete" statement has error in run time.
Can anybody tell me why there is a problem in delete keyword ?
In my concept, when I use "new" keyword, I should use "delete" keyword
to free allocated memory.
void main()
{
string str1="aaa";
string str2="bbb";
string str3="ccc";
string str4="ddd";
int l= str1.length()+ str2.length() + str3.length() + str4.length();
char *mystr = new char[l+1];
sprintf(mystr,"%s,%s,%s,%s", str1.c_str(), str2.c_str(),
str3.c_str(), str4.c_str());
delete [] mystr; //<-----Problem in here!!
}
Thank you very much.
Alan
I have a problem on free allocated memory in C++.
Here is my testing program.
I use VS6.0 to compile it successfully.
But there "delete" statement has error in run time.
Can anybody tell me why there is a problem in delete keyword ?
In my concept, when I use "new" keyword, I should use "delete" keyword
to free allocated memory.
void main()
{
string str1="aaa";
string str2="bbb";
string str3="ccc";
string str4="ddd";
int l= str1.length()+ str2.length() + str3.length() + str4.length();
char *mystr = new char[l+1];
sprintf(mystr,"%s,%s,%s,%s", str1.c_str(), str2.c_str(),
str3.c_str(), str4.c_str());
delete [] mystr; //<-----Problem in here!!
}
Thank you very much.
Alan