I am not able to get it what it means , “error: cannot convert ‘std::string’ to ‘const char*’ ”

// Write a program to find the length of the string “refrigerator”.
#include
using namespace std;
main()
{
string name =“refrigerator”;
int length =strlen(name); // shows Error in this line

cout<<“the size of refrig. is :==”<<length<<endl; return 0; }

if I use char name[ ] = " refrigerator";
then it works fine why it is show error in that line?

to get the size of string type variable u can use
name.size()
or
name.length()
strlen is used for char array

1 Like

@chhavibansal Thank you, now in got it. :slight_smile:

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.