My code has this part which is throwing me an error
for(int i=0;i<100;i++)
{
s=s+",";
cout <<"string length is now "<<s.length<<endl;
}
I am simply appending the same string again and again 100 times to itself.
error is :
line 23: Error: Taking address of the bound function std::basic_string, std::allocator>::length() const.
could anybody tell me what is the wrong i am doing here?
It should be
s.length(), nots.length:Note that
std::string::length()is a function, not a variable.I prefer
.size()because it is consistent with all other containers. Other containers don’t have.length()member function; onlystd::stringhas this function, along with.size()which returns the same value.So if
std::stringhas.size(), then why makes exception and use.length()? Why not use.size()consistently? I would you to suggest use.size()instead of.length():