I'm getting an assertion error in the following script. I'm playing around with strings and trying to identify the string lengths of various ones. The first two worked great. When I tried to do the same thing dynamically. I ran into an assertion error which I am unfamiliar with. The output in the background works, but its taking a dislike to something.
Here is the code:
#include <string.h>
#include <iostream>
using namespace std;
int main () {
char* str1 = "123456";
char str2 [] = "123456789";
char* pstr1 = NULL;
pstr1 = new char[] = "1234567";
cout << "Pointer to char length: " << strlen(str1) << endl
<< "Array length: " << strlen(str2) << endl
<< "Dynamic char array: " << strlen(pstr1) << endl;
delete [] pstr1;
pstr1 = NULL;
return 0;
}
Any help would be greatly appreciated.
Thanks in advance,
Luke


Sign In
Create Account


Back to top









