简体   繁体   中英

getlines undefined in iostream in C++

Here's my code: For some reason, getline is saying undefined. My professor told me that I might be using an older version of C++ but I have no clue how to check it.

I'm using Visual Studio Ultimate 2013. Please save me.

Thanks in advance.

BTW: I don't mind any errors in the code non-relevant to the getline please. The code is not complete but I can't test it when getline is undefined.

#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>标头。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM