Why can I not use the size() value?

P

pkirk25

list<string> mats_list;
list<string>::iterator i;

string s, t;

i = s.size();
if (i > 4)
{
mats_list.push_back(s);
}

Thois errors with:
....main.cpp(19) : error C2679: binary '=' : no operator found which
takes a right-hand operand of type '__w64 unsigned int' (or there is no
acceptable conversion)

i = s.length(); fails the same way.

I am new to C++ so while this may appear a basic question, how can I
use the STL string library to do the equivalent of

char *s = "The answer is 42 - what was the question?";
size_t i = strlen(s);

If (i < 5) {....}

Thanks in advance.
 
G

Gavin Deane

pkirk25 said:
list<string> mats_list;
list<string>::iterator i;

string s, t;

i = s.size();
if (i > 4)
{
mats_list.push_back(s);
}

Thois errors with:
...main.cpp(19) : error C2679: binary '=' : no operator found which
takes a right-hand operand of type '__w64 unsigned int' (or there is no
acceptable conversion)

i = s.length(); fails the same way.

I am new to C++ so while this may appear a basic question, how can I
use the STL string library to do the equivalent of

char *s = "The answer is 42 - what was the question?";
size_t i = strlen(s);

If (i < 5) {....}

std::string::size and std::string::length both return a value of type
std::string::size_type. Your variable i appears to be of type
list<string>::iterator. What makes you think std::string::size_type a
can be converterd to a list<string>::iterator?

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top