Original Post
Hi, I'm a C programmer, and this is how I use dynamic memory in C: <code> char *p = (char *) malloc(256); if (p == NULL) { fprintf(stderr, "get_hello: Cannot allocate 256 bytes\n"); return (NULL); } strcpy(p, "hello world!"); } </code> In C++ I invision doing this: <code> string s("hello world!"); </code> How do I know that there was enough memory to store the "hello world!" string? It's possible the constructor failed to allocate memory, what would happen in that case? What if I do this: <code> string s; s = "hello"; s += " world!"; </code> Than what? it had to do a realloc (ok in the simple example above it probably didn't, but if the second string was big enough that it hadn't preallocated enough memory, it would have to reallocate more space). How do I check the memory allocation that's happening behind the scenes in the string class?