string C++

What is a string in C++ and what is the difference with C-string;
What is the use of string tables in c++;
A string is a data type, defined in the standard library under the header <string>.
A C-string is an array of characters. I generally use the string from the standard library, as it comes with functions like string.length(), and because it has no fixed size (so you can add and remove characters from it, unlike with a C-string).

This is a duplicate.

Also, the length of the buffer and the length of the c-string are not always equal. You absolutely can modify a c-string by adding chars or removing them, so long as the *buffer* is sufficient for this. consider

char cstr[1000];
cstr[0] = 0;
strcat (cstr,"hey");

cstr is a c-string of length 3 of the value "hey" sitting in a huge buffer of 1000 bytes.

strcat(cstr, " you");
now cstr is "hey you"
Last edited on
Topic archived. No new replies allowed.