Can i use strlen()with string type

i typed this code
#include
#include

using namespace std;

int main()
{
string s1, s2;
int t;
cin>>t;
while(t–)
{cin >> s1 >> s2;
int len=strlen(s1);
cout<<len;
}
return 0;
}
WHY IS THERE AN ERROR IN STRLEN PART?

The answer of your query is present in the syntax of strlen() function.

strlen(const char *str)

It is clear from the syntax that it accepts a string of char type as it’s argument.

To use it with the string type you must write the following statement:

strlen(s1.c_str());

Here, c_str() function is used to returns a pointer to an array that contains a null-terminated sequence of characters representing the current value of the string type.

Hope, this would help.
If you still have doubts, feel free to ask.
Give a like if you are satisfied. :wink:

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.