getline:找不到标识符

Posted

技术标签:

【中文标题】getline:找不到标识符【英文标题】:getline: identifier not found 【发布时间】:2015-03-01 13:18:02 【问题描述】:

getline() 有问题。

我尝试了许多示例并阅读了其他解决方案,但这并没有解决我的问题。我还有信息'getline: identifier not found'

我包括 <stdio.h> <tchar.h> <iostream> <conio.h> <stdlib.h> <fstream> 还是什么都没有。

#include "stdafx.h"

using namespace std;

int main(int argc, _TCHAR* argv[])

    string line;
    getline(cin, line);
    cout << "You entered: " << line << endl;

我现在需要做什么?

我使用 Windows 7 64 位和 Visual Studio 2013。

【问题讨论】:

&lt;string&gt; 将是您在其中找到 std::getline 的文件 en.cppreference.com/w/cpp/string/basic_string/getline 胡乱猜测并不是编程的好方法。是什么让您无法简单地在文档中查找此内容? 【参考方案1】:

习惯于简单地阅读文档以了解您使用的语言功能。 cppreference 很清楚,std::getline 可以在 string 中找到。

#include <string>

【讨论】:

【参考方案2】:

这应该可以解决这个问题:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, _TCHAR* argv[])
   string line;
   getline(cin, line);
   cout << "You entered: " << line << endl;

【讨论】:

【参考方案3】:
#include <string>

顺便说一句,“Murach 的 C++ 编程”教科书错误地指出 getline() 位于 iostream 标头中(第 71 页),这可能会导致一些混淆。

【讨论】:

【参考方案4】:

你需要使用

#include "string"

阅读:std::getline

【讨论】:

不是"string",而是&lt;string&gt;,我也遇到了这个问题,使用cppreference

以上是关于getline:找不到标识符的主要内容,如果未能解决你的问题,请参考以下文章

找不到标识符,该怎么解决

error C3861: “maxmin”: 找不到标识符

MFC “DockPane”: 找不到标识符 求解(CDockablePane的)

为啥说找不到标识符!???

找不到标识符 FindFirstFile

点击IE游览器显示找不到映像文件中指定的资源语言标识McShield