Difference between C-Strings and C++ Strings

I have read in a couple of places (these forums included) that Strings in C and C++ are considerably different.
Can someone tell me what those differences are?
I'm fairly sure that in C there is no such thing as a standard string class, you just use arrays of chars.

This might explain it better:

http://www.cprogramming.com/tutorial/lesson9.html
Last edited on
Okay.
So what happens when we use string.c_str() for a C++ string? Does it become an array of chars?
I believe due to historical reason, some commercial C compiler comes with library that does have a string class but all those are non-standard.

Then Standard C++ came along and come out with a string class. This is the standard. But in life, it is not always a bed of roses isn't it ? What if in your work, you need to maintain legacy C code where they do not have string class during their times ?

So to conclude, learn both array of char and also the C++ string class :)
http://www.cplusplus.com/reference/string/string/c_str/

"Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters."

In C every string is terminated by... some character (null character \0?).

Some more reading:
http://en.wikipedia.org/wiki/C_string
:)
Ah!

Thanks a Lot toexii!
If you intend to do a lot of string manipulation for your new C++ program, please use the Standard C++ string class. You will never feel the "pain" those old C coders have during their times when they don't have a proper Standard C string functions to use. Some of the built their own some use commercial C compiler and all are non-standard.

A lot of errors are also attributed to the improper use of array of char or char* for those who attempt to do it the "raw" way without using the C string functions like strcat, strcpy etc.
Interesting read
Topic archived. No new replies allowed.