patryk77

November 26th, 2009, 02:21 AM

Hey,

I am having a weird bug when trying to use

if (curPos != string::npos)

It never evaluates to true when using the string find functions. The following works:

if (curPos != (unsigned int) -1)

If I cout << curPos, I get 4294967295 (which I expect as it should be (unsigned int) -1).

If I cout << string::npos, I get 18446744073709551615

Is that simply because I am on a 64-bit platform, and size_t is 64-bits?

Is using (unsigned int) -1 in my comparisons the correct way of dealing with this?

Thanks.

I am having a weird bug when trying to use

if (curPos != string::npos)

It never evaluates to true when using the string find functions. The following works:

if (curPos != (unsigned int) -1)

If I cout << curPos, I get 4294967295 (which I expect as it should be (unsigned int) -1).

If I cout << string::npos, I get 18446744073709551615

Is that simply because I am on a 64-bit platform, and size_t is 64-bits?

Is using (unsigned int) -1 in my comparisons the correct way of dealing with this?

Thanks.