Can't argue with that. Oh, perhaps you should get more used to C++ strings.
Originally Posted by sean_mackrory
Which is really not an issue in a program that uses cout and cin.
It's not about knowledge of the language, it's about common sense. The C++ string behaves like a built-in type, it just makes sense. The C-style string doesn't.
3) Personally I thought C-style strings would be easier for newbies to grasp since they wouldn't have done much OOP yet, but I'm not one to argue with someone with as much knowledge of the language as Prelude.
Just a few examples. I'm assuming "using std::string". I want to put a string literal into a variable.
Yes, the syntax becomes second nature to C programmers, but newbies?
string str = "Hello, World!";
const char *str = "Hello, World!"; /* What is "const char *"?
Why can't I say "char *"? The compiler allows it. Why can't I modify it? */
char str = "Hello, World!"; /* "char "? Weird syntax. */
String copying with unknown size:
Again, all those questions. What is malloc? What is strlen? Why can't I just say str2 = str1? Why do I have to remember to free? Why shouldn't I return such stuff from a function?
string str2 = str1;
char *str2 = malloc(strlen(str1)+1);
/* And don't forget to free! */
The code is getting longer.
str1 += str2;
C: (assuming that str1 was allocated with malloc)
char *t = malloc(strlen(str1)+strlen(str2)+1);
str1 = t;
There are more issues. Buffer sizes. Why do I have to watch for buffer overflows? What is that, anyway? Why can't I return a local buffer from a function?
And have you so far seen any signs of OOP in the C++ version? Anything that newbies would have to understand in order to use string? No, since it's a perfect blackbox. It might as well be built-in.
Bottom line: newbies usually want to do things now, and later learn the whys and hows. It's simply more fun that way.