在 C++ 年的 iostream 中未定义的获取线

getlines undefined in iostream in C++

本文关键字:获取 未定义 C++ 年的 iostream      更新时间:2023-10-16

这是我的代码:出于某种原因,getline说未定义。我的教授告诉我,我可能使用的是旧版本的C++,但我不知道如何检查它。

我正在使用Visual Studio Ultimate 2013。请救救我。

提前谢谢。

顺便说一句:我不介意代码中与getline无关的任何错误。代码不完整,但当getline未定义时我无法测试它。

#include <iostream> 
using namespace std;
int main()
{
    string concatenatedLines;
    getline(cin, concatenatedLines);
    if (!cin)
    { // C++ can overwrite conversion operator... cin is being converter into a boolean operator. It is FALSE if you attempted to read and there's nothing there.
        return 1;
    }
    // START OF MISSING CODE *-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=
    //
    int numberOfLines = 1;
    int stat = 0;
    string line;
    string space = " ";
    while (stat == 0)
    {
        getline(cin, line);
        if (!cin) stat = 1;
        else{
            concatenatedLines = line + space + concatenatedLines;
            numberOfLines++;
        }
    }
    //
    // END OF MISSING CODE *-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=
    cout << concatenatedLines << endl;
    //endl = end of the line - declared in the standart library
    cout << concatenatedLines << endl;
    return 0;
}

您还需要包含<string>标头。