2017-01-09 144 views
-2

ここに私のコードです: 何らかの理由で、getlineは定義されていません。私の教授は、古いバージョンのC++を使用しているかもしれないと教えてくれましたが、チェックする方法はわかりません。C++のiostreamでgetlineが未定義

私は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; 
} 
+3

'string'ヘッダーを含めます。 –

答えて

1

また、<string>ヘッダーを含める必要があります。