Reputation: 1215
It is given in the STL reference that string class is in string header,then without including the header how the following program is running without an error??
#include<iostream>
using namespace std;
int main() {
string s;
cin>>s;
cout<<"string entered is : "<<s;
}
I am using a g++ complier on ubuntu machine.
Upvotes: 2
Views: 447
Reputation: 116704
Perhaps because iostream
itself includes string
in that compiler's implementation of the libraries. But this is not the case in other library implementations, e.g. Microsoft's VC++ doesn't allow this.
You shouldn't rely on that kind of implicit inclusion, as it varies from compiler to compiler, and even from version to version (I'm currently trying to build some old std:: c++ code in Visual Studio 2010 and there's been at least one extra include I've had to put in.)
Upvotes: 7