lundi 19 décembre 2022

C++. I get an error on the for loop vector push_back [duplicate]

I get an |65|error: no match for 'operator<<' (operand types are 'std::basic_ostream' and '__gnu_cxx::__alloc_traitsstd::allocator<Reservation::information, Reservation::information>::value_type' {aka 'Reservation::information'})| I'm a beginner using vector, please help me. I'm trying to create a reservation that ask information of the user, however I getting an error.I dont know what to do. Any ideas?

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

void details();

class Reservation{
    private:
struct information
    {
    string name;
    string mobileNum;
    };

    vector<information> list_of_reservation;


public:

void details()
{
string back;
information l;

    cout << "WELCOME TO AIRLINES\n";

    for (int i = 0; i < 100; i++){
    cout << "What is your name: ";
    cin >> ws;
    getline (cin, l.name);
    cout << "What is your number: ";
    cin >> l.mobileNum;
    back:
        cout << "Do you want another reservation? Y/N:";
        cin >> back;

         if (back == "Y" || back == "y")
    {
        cout << endl
             << endl;
        cout << "You filled all Entries of traveler successfully...\n";
    }
    else if (back == "N" || back == "n")
    {
        cout << endl
             << endl;
        cout << "You filled all Entries of traveler successfully...\n";
        break;
    }
    else
    {
        cout << "Wrong Input";
        goto back;
    }
    list_of_reservation.push_back(l);
}


    cout << "You entered: " << list_of_reservation.size() << endl;
    for (int i = 0; i < list_of_reservation.size(); i++)
    {
        cout << "the names are: " << list_of_reservation[i] << endl;
    }
    /*for (int i = 0; i < m.list_of_mobileNum.size(); i++)
    {
        cout << "the numbers are: " << m.list_of_mobileNum[i] << endl;
    }*/
}
};


int main(){


    cout << "Welcome to airlines details please confirm\n";
    Reservation obj;
    obj.details();


    return 0;
}

Aucun commentaire:

Enregistrer un commentaire