首页 > 解决方案 > 是否不再需要字符串头文件?

问题描述

所以我现在正在学习 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;

}

标签: c++stringheader

解决方案


一些编译器实现在标头<string>中包含标头<iostream>

但是你不能依赖这个。


推荐阅读