when i am executing cout<<strlen("a vinash"); in the main function, i am getting output as 7....but whereas if i execute as following
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string a = "avinash";
cout<<strlen(a) ;
}
Now, i am getting an error that cannot covert std::string ot const chat* for argument 1 to size_t strlen(const char*)
but if do using string length, i am getting the perfect answer
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string a = "avinash";
cout<<a.length( );
}
Now i am getting the correct output as 7
can u please tell me why i am unable to get the same output using cout<<strlen(a) ;
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string a = "avinash";
cout<<strlen(a) ;
}
Now, i am getting an error that cannot covert std::string ot const chat* for argument 1 to size_t strlen(const char*)
but if do using string length, i am getting the perfect answer
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string a = "avinash";
cout<<a.length( );
}
Now i am getting the correct output as 7
can u please tell me why i am unable to get the same output using cout<<strlen(a) ;
Comment