Is there a potential problem with this line of code?
-
int begin, end; // search through using STL stringObject.find("searchForString") if( (begin != string::npos) && (end != string::npos)) // Warning: warning C4389: '!=' : signed/unsigned mismatch Thanks in advance!
I guess
string::npos
isunsigned integer
type hence the warning. Do not do logical operations(particularly in loops) withsigned
andunsigned
types. This could lead to infinite loops and other unprecedented results.
Nibu thomas Software Developer
-
int begin, end; // search through using STL stringObject.find("searchForString") if( (begin != string::npos) && (end != string::npos)) // Warning: warning C4389: '!=' : signed/unsigned mismatch Thanks in advance!
Use
string::size_type
instead ofint
for thebegin
andend
variables so they match the type returned bystring::npos
. You shouldn't mix signed and unsigned types in a conditional statement unless you really know what you're doing (and are willing to handle the consequences ;)).Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"