"<<" operand doesn't work with an array of string in visual studio2012 [duplicate]

StackOverflow https://stackoverflow.com/questions/19216336

  •  30-06-2022
  •  | 
  •  

문제

This is the class "Date.h"

class Date
{
    private: 
        int day;
        int month;
        int year;

    public:         
        void PrintDateV2();
        Date(int, int, int);
        ~Date();

};

This is "Date.cpp" with the implementation of the specified function that doesnt work

void Date::PrintDateV2()
{
    string months[12]={"January", "February", "March", "April", "May", "June", "July",           "August", "September", "October", "November", "December"};
   /*line of error*/cout << months[month-1] << endl;//<< ":: " << day << ", " << year << endl;
}

this is the error in visual studio in error list:

no operator "<<" matches these operands operand types are: std::basic_ostream char, std::char_traits> << std::string

도움이 되었습니까?

해결책

You forgot

#include <string>

in your program before using operator<<.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top