2017-01-09 109 views
-2

以下是我的代碼: 由於某些原因,getline表示未定義。我的教授告訴我,我可能會使用舊版本的C++,但我不知道如何檢查它。getlines在C++中的iostream中未定義

我正在使用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>標頭。