By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Why can I not use the size() value?

P: n/a
list<stringmats_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.

Oct 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

pkirk25 wrote:
list<stringmats_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

Oct 3 '06 #2

P: n/a
Thanks. Works fine now.

Oct 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.