Containers & Iterators sanity check

E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm using g++ 3.4.2 & am having trouble with algorithms (find) and
strings. Here's my code:

string::iterator itor = find(input.begin(), input.end(), "|");

I'm fairly sure this code worked for me in the past, as I am working out
of the same reference material I have used on previous compilers. I just
can't figure out why I am getting the following error:

/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:207:
error: ISO C++ forbids comparison between pointer and integer


Any help would be greatly appreciated.

Evan Carew
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFDsz8rpxCQXwV2bJARAuWJAKCHdbS2VQ6pBC6/cyPaTqXK6bd2KwCdE7xB
KnXpB8StjZ7CFH92Nz94Ino=
=jzu9
-----END PGP SIGNATURE-----
 
D

Dietmar Kuehl

Evan said:
I'm using g++ 3.4.2 & am having trouble with algorithms (find) and
strings. Here's my code:

string::iterator itor = find(input.begin(), input.end(), "|");

I'm fairly sure this code worked for me in the past, as I am working out
of the same reference material I have used on previous compilers.

I'm fairly sure this code *never* worked. However, this will:

string::iterator itor = find(input.begin(), input.end(), '|');

The key difference is to pass a character rather than string literal
as the value argument.
 
E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dietmar said:
I'm fairly sure this code *never* worked. However, this will:

string::iterator itor = find(input.begin(), input.end(), '|');

The key difference is to pass a character rather than string literal
as the value argument.
Argggh! I could have looked at that code all night & not seen the double
quotes. Thanks.

Evan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFDs0WFpxCQXwV2bJARAjdEAKC2k0OP/JSJCgAtZPtYzPrG65hxKACeKFeZ
nGiRmXgfap/q+PIZJczA4V0=
=S8aH
-----END PGP SIGNATURE-----
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top