SilverNightaFall
SilverNightaFall

Reputation: 4170

number of characters in the string

I am new to c++ and I am trying to figure out how to set an int variable place to the number of characters in the string variable name using the length() function.

Would it be something like this?

place.length() = length(name);

Upvotes: 0

Views: 725

Answers (2)

jli
jli

Reputation: 6623

If I understand the question, its something like:

int place = name.size();

Remember that the string::size() member function returns a size_t, so you may want to consider storing the size in a size_t or at least an unsigned int.

Upvotes: 4

moshbear
moshbear

Reputation: 3322

C++ doesn't have a std::length(const C&) function.

Are you looking for non-static member function std::string::size_type std::string::size() const?

Upvotes: 1

Related Questions