I assume by size_type you mean the typedef inside most STL containers?
If so, then just because size_type was added to all the containers instead
of just using size_t means that the STL is reserving the right to make
size_type any type they like. (By default, in all implementations I'm aware
of size_type is a typedef of size_t).
1) in which libraries is size_t defined or present in? because I discovered that including either cstdlib or iostream would define size_t.
2) what datatype exactly is size_t typedef to?
3) in which libraries is size_type defined or present in?
4) since size_type is almost always typedef to size_t, I guess most of the time it would be of size_t type, am I right?
5) When and where are size_t and size_type used? because when I compare the result of an int and the result of member function length() of string class, it gives me a warning comparison of signed and unsigned types.
1.) Probably most things that use a size_type variable (since they typedef it to size_t like jsmith said, they need to include whatever has it)
2.) Idr, it's probably an unsignedint or an unsignedlongint.
3.) AFAIK, all of the STL containers/stuff that would have a size() member function.
4.) Yes, most of the time.
4.) The warning it because size_t/size_type are unsigned types. They are used when you call the size() member function (and possibly other functions that return size-like variables)
the size member function returns a size_type but when I try to delcare a size_type variable as in size_type a; in my program after including the string library I get this error:
error: ‘size_type’ was not declared in this scope
why is this happening and how do I resolve this problem?
btw, where can I find all the typedefs and function prototypes of each library? I'm using linux...
so to play safe, I should use size_type whenever size_type is specified as a parameter/return value as on the cpp reference and size_t when specified as such right? so that whenever the implementation changes I wouldn't have to change my program unlike when I used int in the past in place of size_t and size_type