#include<bits/stdc++.h>
using namespace std;
int main()
{
string str="ABC";
int n=strlen(str);
cout<<n;
}
This shows error which is:
error: cannot convert ‘std::string {aka std::basic_string}’ to ‘const char*’ for argument ‘1’ to ‘size_t strlen(const char*)’
int n=strlen(str);
But this works fine:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char str[]="ABC";
int n=strlen(str);
cout<<n;
}
What is the reason behind this?