如何在没有#include <string>的情况下使用字符串?

deo*_*ngh 0 c++

在STL引用中给出了字符串类在字符串头中,然后不包括头如何运行以下程序而没有错误?

#include<iostream>

using namespace std;

int main() {
  string s;
  cin>>s;
  cout<<"string entered is : "<<s;
}
Run Code Online (Sandbox Code Playgroud)

我在ubuntu机器上使用g ++编译器.

Dan*_*ker 7

也许是因为iostream它本身包含string在编译器的库实现中.但在其他库实现中并非如此,例如Microsoft的VC++不允许这样做.

你不应该依赖那种隐式包含,因为它从编译器到编译器,甚至从版本到版本各不相同(我目前正在尝试在Visual Studio 2010中构建一些旧的std :: c ++代码,并且至少一个额外的包括我必须投入.)