I have been trying to find the length of string
which has an array of char
s with strlen()
function but it is not working.
The code I am using is something like this:
string s[]={"a","b","c"};
int len = strlen(s.c_str());
It produces the following error:
"request for member âc_strâ in âwArrayâ, which is of non-class type"
But when I have used this strlen()
function on string
s before like this, it worked fine:
fin.open("input.txt");
string tempStr;
getline(fin, tempStr,'\n');
int len = strlen(tempStr.c_str());
What I am missing here? I know I can find the length of string s[]
with
int size = sizeof( s ) / sizeof( s[ 0 ] );
But why can't I use strlen()
. Can someone explain what is going on?