本文介绍了打印出对象矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印出对象的矢量但是当我使用cout<<它给出了如下所示的错误。请提供有关如何迭代和打印存储在对象中的信息的建议。



I am trying to print out the vector of objects but when I used the cout<< it gives error as shown below. Please provide advise on how to iterate and print out the information stored in the objects.

#include <iostream>
#include <vector>
#include <list>
#include<fstream>
using namespace std;

class Date
{

public:
   int day;
   int month;
   int year;

   Date(int day, int month, int year): day(day), month(month), year(year) {};
};

int main ()

{
    vector <Date> date;

        date.push_back(Date(2, 3, 1980));
        date.push_back(Date(5, 4, 1982));
        date.push_back(Date(1, 6, 1989));

        for(auto it = date.begin(); it != date.end(); it++)
        {
            cout<<*it<<endl; //Get error message

        }



    return 0;

}

推荐答案


这篇关于打印出对象矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:44
查看更多