size_type type

The string class type and the type of vector class type definitions, to save the length of any string objects or vector objects, the library types size_type defined as unsigned type

string :: size_type it on different machines, may be of different length, not a fixed length. But as long as you use this type of program makes you suitable for this machine. Match the actual machine.

string :: size_type in essence, is an integer. The key is because the machine's environment, its length may vary. For example: We use the string :: find function of time, it is the return of the type string :: size_type type. And when the find can not find're looking for character, it returns the value of npos, this value is related to the size_type.

If you use a string s; int rc = s.find (.....); and determining, if (rc == string :: npos) so that the performance on different platforms is not the same machine. If the length of the string :: size_type your platform just int and matches, then the judge will be lucky enough to correct. But replaced by another platform, it is possible size_type of type string :: length is 64, then the judge is completely correct. Therefore, the correct should be: string :: size_type rc = s.find (.....); this time use if (rc == string :: npos) on the back correctly.

  st.size () indicates the number of characters st, the number of characters to begin accumulating statistics are calculated by the 1, so the number of characters just, index here than the index number (starting from 0 cumulative) index string of big 1! = st.size (); same effect as index <st.size ();

 

Overall is a member of the string and vector function return values ​​are size_type types, not simply an int, and so on. So good luck may not detect errors, bad luck to die.

Guess you like

Origin www.cnblogs.com/pacino12134/p/10988653.html