iostream header include string header?

1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
int main()
{
      string a;
      while(cin>>a)
	    cout<<a<<endl;
      return 0;
}


I have not included the string header,but it works .It seems iostream include it
Standard headers can include other headers so this is probably the case here. If you want to make sure it works on all compilers you have to include <string>.
GNU's implementation, in particular, does include string in iostream but I believe the correct thing to do for portability is to include both explicitly.
closed account (S6k9GNh0)
The same code won't compile on VC++. Especially with the standard headers, you generally want to explicitly include individual headers to maintain flexibility.
Last edited on
thank all very much
Topic archived. No new replies allowed.