【发布时间】:2019-08-13 16:29:02
【问题描述】:
所以我现在正在学习 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;
}
【问题讨论】:
-
请出示您的代码。
-
简短的回答是肯定的,您确实需要包含标题。我的猜测是您正在包含另一个标题,该标题本身包含
string一个。没有看到你的代码,我们无法给你一个明确的答案。