Get string length

Hi there!
I´m trying to get the length of a string, but I get error when I do:


strlen(Ficha.Market);

Market is a string, inside Ficha struct:

1
2
3
4
5
6
struct Ficha{
       string name;
       int ID;
       string Market;
       ...
       }


The error says:
"no matching function for call to `strlen(std::string&)'

I´ve seen that strlen is used with char* types, but cant it be used with strings as well?

I cannot change the type in the struct because I use strings methods, such as append()...

I´ve included:
1
2
3
#include <string>
#include <stdlib.h>
#include <stdio.h> 


any ideas?
Ty in advance
Last edited on
I´ve seen that strlen is used with char* types, but cant it be used with strings as well?


No.

Take a look at the string class member functions; it provides its own length function.

http://www.cplusplus.com/reference/string/string/length/

int lengthOfString = someString.length();
Last edited on
Thats it,
Much Appreciated...
What about get some range inside a string?

for example:

string name="Mr David White";

I want to get just "White".

Something like name[8..end]

Ty
Topic archived. No new replies allowed.