Eagleboy has the words of truth.
Anyway, the "hassle" is often necessary because everyone wants to avoid nasty situations where you get an error simply because you get either a memory overflow, or then you need some important string and half of it gets cropped away.
char *whatever;
whatever = new char[size+1];
strcpy(whatever, "hello");
delete [] whatever;
The above piece of code allows you to dynamically adjust the size of the string... which is sure to happen often. If you want to use this:
char whatever[] = "hello";
Then why not write
const char whatever[] = "hello";
because it is less prone to errors. The one that you suggested being easier... well yes, but try to insert "hellototheentireworld" into the same variable
My point is that you cannot resize the char variable if you don''t use pointer. If you need a static string, then it might be good to make it const to avoid errors.
- A.J. -
"Where is the KABOOM!? There was supposed to be an earth-shattering KABOOM!"
- A.J. -"Where is the KABOOM!? There was supposed to be an earth-shattering KABOOM!"