c++ - "<<" operand doesn't work with an array of string in visual studio2012 -


this question has answer here:

this class "date.h"

class date {     private:          int day;         int month;         int year;      public:                  void printdatev2();         date(int, int, int);         ~date();  }; 

this "date.cpp" implementation of specified function 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 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 program before using operator<<.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -