You forgot
#include <string>
in your program before using operator<<
.
Question
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
Solution
You forgot
#include <string>
in your program before using operator<<
.