0

問題が発生しており、修正方法がわかりません。

これは、エラーを受け取った元の検索機能です。

void guestSearch()
{
    &Reservation::getfirstName;
    &Reservation::getlastName;

    &Date::getday;
    &Date::getmonth;
    &Date::getyear;
    Hotelreservation reg;
    reg.duration;
    reg.occupants;
    &Contact::getareaCode;
    &Contact::getexchange;
    &Contact::getline;

    system("cls");
    cout<<"Enter Line Number for the Guest you are searching for:";
    cin>>line;
    string line2= to_string(line);
    line2.append(".txt");

    ifstream filemain(line2);
    while(firstName>>lastName>>day>>month>>year>>duration>>occupants>>areaCode>>exchange>>line)
    {
        int firstNameLength=firstName.size();
        int lastNameLength=lastName.size();
        int lengthTotal=firstName+lastName;

        string result;
        cout<< "Is this the correct Guest (y/n)"<<endl;
        cout<<"Name"<<firstName<<" "<<lastName<<end;
        cin>>result;

        if(result=="y")
        {
            system("cls");
            cout<<"Name";
            for(int y = 1; y<lengthTotal; y++)
            {
                cout<< " ";
            }
            cout<<"Reservation Date";
            for(int z=1; z<2; z++)
            {
                cout<< " ";
            }
            cout<<"Duration of Stay";
            for(int x=1; x<2; x++)
            {
                cout<< " ";
            }
            cout<<"Occupants";
            for(int u=1; u<2; u++)
            {
                cout<< " ";
            }
            cout<<"Contact Number";
            for(int v=1; v<2; v++)
            {
                cout<< " ";
            }
        }
        cout<<"Date Reservation was made:"<<day<<"/"<<month<<"/"<<year<<endl;
        cout<<"Duration Of Stay:"<<duration<<endl;
        cout<<"Occupants:"<<occupants<<endl;
        cout<<"Contact Number:"<<areaCode<<"-"<<exchange<<"-"<<line<<endl;
    }
}

の後に while 宣言でエラーが発生しました。次のように表示されfirstName ">>"ます。

IntelliSense: no operator ">>" はこれらのオペランドに一致します。オペランドの型は次のとおりです: std::string>>std::string"

4

1 に答える 1

1

概念を誤解していますが、複数のstd::stringインスタンスを連鎖させることは可能ですが、最初のオブジェクトは、あなたの場合のようにoperator >>継承された型でなければなりません:std::istreamifstream fileman

while( fileman >> firstName >> lastName >> ... )

その式を次のように扱うことができるため、機能します。

while( fileman.operator>>( firstName ).operator>>( lastName ) ... )

また、チェーン呼び出しが機能するstd::istream::operator>>参照を再度返すためです。std::istream

そのような演算子はありませんstd::string

于 2014-11-13T14:51:40.707 に答える