dimanche 29 décembre 2019

How to print array which I use in a map?

Here is my code:

typedef array<int,6> Array;
Array dayHours{0,0,0,0,0,0};

I am using this data in here:

void Schedule::studentSchedule()
{
    string c, s;
    int courseNum;
    list<string>::iterator studentLoc;
    map<pair<string, int>, pair<string, Array> >::iterator location;

    cout << "Enter the student name" << endl;
    cin >> s;
    cout << "Enter how many course you want?" << endl;
    cin >> courseNum;
wrongCourse:
    cout << "Enter the course names you want" << endl;
    for (int i = 0; i < courseNum; ++i)
    {
        cin >> c;
        auto predicate = [&](auto& course) { return compareName(course, c); };
        studentLoc = find(getStudentList().begin(), getStudentList().end(), s);
        location = find_if(getMatchMap().begin(), getMatchMap().end(), predicate);
        map<pair<string, int>, pair<string, Array> >::iterator it;
        cout << "Student:\t\t" << "Course:\t\t" << "Course Day:\t\t" << "Course Hours:" << endl;
        if (studentLoc != getStudentList().end() && location != getMatchMap().end())
        {
            getCourseScList().insert({ make_pair(s,c),make_pair(getDay1()[i],getDayHours()) });
        }
        else
        {
            cout << "The course you're writing isn't available.Please enter existed courses!" << endl;
            goto wrongCourse;
        }
    }
}

I am sending the array to the map here:

if (studentLoc != getStudentList().end() && location != getMatchMap().end())
{
    getCourseScList().insert({ make_pair(s,c),make_pair(getDay1()[i],getDayHours())});
}

The question is how can I reach the array element:

map< pair<string, string>, pair<string, Array> >::iterator last;
for (last = getCourseScList().begin(); last != getCourseScList().end(); ++last)
{
    cout << (last->first).first << "\t\t\t\t"
         << (last->first).second
         << "\t\t" << (last->second).first
         << (last->second).second << endl;
}

The (last->second).second is representing my array but I can not print this to screen. What can I do?

Aucun commentaire:

Enregistrer un commentaire