why I can use the string function length() when the <string> isn't included in C++? -


the code shown following, string library has been commented, program still work well

#include<iostream> //#include<string>   // string library has been commented  using namespace std;  int main(){     int n;     cin>>n;     for(int i=0; i<n; i++){         string str;         int num = 0;         cin>>str;         int len = str.length();    //the function length used here!         (int j =0; j< len; j++){            if (str[j] >='0' && str[j] <='9')                num ++;         }      cout<<num<<endl;     }     return 0; } 

because internally iostream includes string.

includes transitive, , of dependencies might compiler dependent, while others same on platforms (one such example including map make pair available, depends on directly).

the dependency between string , iostream isn't defined anywhere, while might work on compilers, shouldn't depend on it.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -