是否不再需要字符串头文件?

Sto*_*rMy 0 c++ string header

因此,我目前正在学习C ++,有时我看到您“必须” #include <string>在代码的顶部使用字符串。但是,当我运行我的代码时,在两种情况下它都做同样的事情。真的需要使用吗?

#include <iostream>
using namespace std;

int main() 
{
    string fullName;
    cout << "Type your full name: "; 
    getline(cin, fullName);
    cout << "Your name is: " << fullName;

}
Run Code Online (Sandbox Code Playgroud)

Vla*_*cow 6

一些编译器实现将header包含在header <string><iostream>

但是您不应该依赖于此。