Use of c.str() and What did you mean by underlying string array?

What did you mean by underlying string array? I don’t understand that part and therefore I don’t get what c.str() actually does. I tried a lot looking on the internet about c.str() but I’m not able to understand what it acutally does.

Many places it said it returns pointer but how? How does it return pointer of a string? Both are different data types. Initially it’s a string data type how could it return pointer of a string?

And why does simply doing char *c=str gives error?

hello @noobmaster69

see string is a class in c++ but strtok takes char * in its input .
so thats why we are using c_str function . it converts the c++ string into c based string(char *) and returns its base address.

it converts c++ string into c based string and then return based address of c based string.

str is object of string , c is a pointer. we cannot store object int pointer as both are of different type

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.