【问题标题】:getline: identifier not foundgetline:找不到标识符
【发布时间】: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。

【问题讨论】:

标签: c++ visual-studio-2013 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
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 2015-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多