2013-04-23 76 views
1

我有多項式類。我也有一種方法可以將字符串轉換爲多項式。 現在我試圖實現輸入操作此方法:獲取字符串只在超載>>運算符istream:

istream& operator>> (istream &is, Poly& pol) 
{ 
    //the string that we use: 
    string str; 

    //the new input override the old: 
    pol.emptyPoly(); 


    //getting a string from user and put it into str: 
    //????????????????????? 

    // convert the string to polynomial 
    pol.sToPol(str); 

    return is; 
} 

我是什麼需要投入// ????????從用戶獲取字符串並將其放入str?

然後當我將做:

Poly p1; 
cin>>p1; 

用戶將輸入字符串,如果字符串是沒有空格它將被轉換成多項式在我的方法

回答

3
is >> str; 

std::getline(is, str); 

如果字符串中有空格。

+0

謝謝,但它不工作。 第一個靈魂給我錯誤: 錯誤C2678:二進制'>>':沒有找到操作符,它需要類型'std :: istream'的左側操作數(或沒有可接受的轉換) 第二個不找到getline std – 2013-04-23 09:58:03

+1

@AviadChmelnik怎麼樣#include ? – ForEveR 2013-04-23 10:08:43

+0

我試圖編輯評論:「我的錯誤!,忘了寫包括字符串」但5分鐘的編輯結束了。 非常感謝很多人!你可以在「OOP簡介」中保存我的成績:) – 2013-04-23 10:23:11