0

Trying to print an element from my array of strings. Marked comment where error is.

Getting the errors:

  1. IntelliSense: no operator "<<" matches these operands operand types are: 
    std::ostream << const std::string
    
  2. error C2679: binary '<<' : no operator found which takes a right-hand operand
    of type 'const std::string' (or there is no acceptable conversion)
    

#include <iostream>
using namespace std;

int main()
{
    int day = 5, year = 2015;


    const string months[13] = { 0, "January", "February", "March", "April", 
                               "May", "June", "July", "August", "September",
                              "October", "November", "December" };

    cout << months[5] << " " << day << ", " << year << endl;  //the first << is the issue
}

1 Answer 1

3

You didn't #include <string>, you were lucky enough that some parts of <string> were found in <iostream> so you could declare months.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, thanks. Another problem occurs after I added string. I get debug assertion failed and have to abort. Any idea why this happens?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.