MonthNames[0] = "Januaray";
	MonthNames[1] = "Febuary";
	MonthNames[2] = "March";
	MonthNames[3] = "April";
	MonthNames[4] = "May";
	MonthNames[5] = "June";
	MonthNames[6] = "July";
	MonthNames[7] = "August";
	MonthNames[8] = "September";
	MonthNames[9] = "October";
	MonthNames[10] = "November";
	MonthNames[11] = "December";

	for(int n = 0; n < 12; n++)
	{
		cout << MonthNames[n] << endl;
	}

Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Dani AI

Generated

This is the classic "missing standard-header" symptom: the compiler knows the string type but it cannot find the iostream insertion overload for it. As pointed out, the immediate cause was a missing header; 's clarification about being able to create string objects but still needing the header for operators is exactly right — some headers only declare types or bring them into scope, while the insertion operator overloads live in the appropriate standard-library headers and must be visible at compile time.

Quick checklist for the same error in other codebases:

  • Verify the string type is actually std::string (not a custom type or char* array).
  • Include the standard headers that define the string type and stream operators (and do not rely on transitive includes).
  • Make sure the translation unit is compiled as C++, not C.
  • Watch for name collisions or user-defined operator<< overloads that could hide the standard one.
  • Avoid leaving using namespace std; in headers — prefer explicit std:: to reduce surprises.

Modern, safer patterns that avoid repetitive assignment and reduce this class of mistake: use an initializer list and a container, and print with a range-based loop (example below shows the pattern; it is not the same code as the original post).

#include <iostream>
#include <string>
#include <array>

int main() {
    std::array<std::string, 12> months = {
        "January","February","March","April",
        "May","June","July","August",
        "September","October","November","December"
    };
    for (const auto &m : months) std::cout << m << '\n';
}

Also note the spelling typos in the original month literals (for example, "Januaray" and "Febuary") — fixing typos avoids confusing test output when validating results.

Recommended Answers

All 3 Replies

Include the <string> header.

DOH! wow guys, I apologize to who ever looked at this thread. Dont judge me =(

DOH! wow guys, I apologize to who ever looked at this thread. Dont judge me =(

just remember, you can create instances of the std::string class without the header. But, in order to do anything with them, you need it because that's where all the functions/operators are defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.