2016-08-23 11 views
0

私は私の問題に対する妥当な答えについてすでに研究していました。私は大学のプロジェクトをやっていますが、他のコードで見つかった文字列包含エラーはありません。何が起こっているのかについてのヒントを教えてください。C2679 tバイナリ '>>': 'const std :: string'型の右辺のオペランドを取る演算子が見つかりません。(または受け入れ可能な変換はありません)

エラー

C2679 binary '>>': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion) PhoneCall2 c:\users\mano\documents\visual studio 2015\projects\phonecall2\phonecall2\phonecall.h 25 

コード

#include <iostream> 
#include <istream> 
#include <string> 
using namespace std; 

class PhoneCall 
{ 
public: 
    PhoneCall(); 
    PhoneCall(string, int); 
    ~PhoneCall(); 

private: 
    string phoneNumber; 
    int length; 
    double static ratePerMinute; 

    friend ostream &operator << (ostream &output, const PhoneCall &Call) { 
     output << "Phone number :" << Call.phoneNumber<<"Length :"<<Call.length; 
     return output; 
    } 

    friend istream &operator >> (istream &input, const PhoneCall &Call) { 
     input >> Call.phoneNumber >> Call.length; \\right here. 
     return input; 
    } 

    friend bool operator==(const PhoneCall &p1, const PhoneCall &p2); 
    friend bool operator !=(const PhoneCall &p1, const PhoneCall &p2); 
}; 
double PhoneCall::ratePerMinute = 0.00; 

PhoneCall::PhoneCall() { 
    phoneNumber = ""; 
    length = 0; 
} 

PhoneCall::PhoneCall(string c, int m) { 
    phoneNumber = c; 
    length = m; 
} 

bool operator==(const PhoneCall &p1, const PhoneCall &p2){ 
    return (p1.phoneNumber == p2.phoneNumber); 
} 
bool operator!=(const PhoneCall &p1, const PhoneCall &p2){ 
    return !(p1.phoneNumber == p2.phoneNumber); 
} 

PhoneCall::~PhoneCall() {}` 

答えて

0

を参照してください、あなたはoperator>>の機能ヘッダにconst PhoneCall &Callを持っており、関数の内部で、あなたはconstオブジェクトを変更しています、これを削除してみてくださいconst

friend istream &operator >> (istream &input, PhoneCall &Call) { 
    input >> Call.phoneNumber >> Call.length; 
    return input; 
} 
関連する問題

 関連する問題