Int Pos = Str. Find ("\ t ");
If (Pos = string: NPOs) in the above Code, the POs type is defined as int, which is incorrect, even if it is defined as unsigned int, it must be defined as string: size_type.
In C ++, NPOs is defined as follows:
Static const size_type NPOs =-1;
Because string: size_type (defined by the string configurator Allocator) describes size, it must be an unsigned integer. Because the default configurator uses size_t as the size_type,-1 is converted to an unsigned integer, and NPOs becomes the maximum unsigned value of this type. However, the actual value depends on the actual definition of size_type. Unfortunately, these maximum values are different. In fact, (unsigned long)-1 and (unsigned short)-1 are different (provided that the two types have different sizes ). Therefore, the comparative POS ==string: NPOs
If the POs value is-1, the comparison result may be false because the POs type is different from the string: NPOs type.
To determine whether the result of find () is string: NPOs, the best way is to directly compare:
If (Str. Find ("\ t") = string: NPOs ){... }
Reprinted from: http://www.cppblog.com/ming81/archive/2011/04/15/144290.html