strlen()
is for C const char*
strings. To get the length of a string s
, use s.size()
or s.length()
. If you want to get a C string from a string
, use s.c_str()
.
Although C++ makes it seem that const char*
and string
are interchangeable, that only goes one way when converting const char*
to string
.
There is no reason why you would want to use strlen
either. strlen
is most likely defined with a loop, which will never be as efficiant as size()
, which is most likley just a getter for a length property of the string
class. Only convert string
to C strings when calling C functions for which there is not a C++ alternative.