I'm using VS 2010 and I always get multiple error messages:

'<<': no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion). I get that for lines 36 and 52.

Then I get "Intellisense: no operator "<<" matches these operands for lines 36 and 51.

"Intellisense: cannot open source file "stream"

warningC4627: '#include <stream>': skipped when looking for precompiled header use

When I try to run without debugging it says '"filepath name"' is not recognized as an internal or external command, operable program or batch file.

What's wrong with my code? I copied it write out of a tutorial book and am very confused.

// Fig37.cpp : Defines the entry point for the console application.
// Instantiating multiple objects of the GradeBook name and using
// the GradeBook constructor to specify the course name
// when each GradeBook object is created
#include <iostream>
#inclide <stream>
#include "StdAfx.h"
using namespace std;

// GradeBook class definition
class GradeBook
{
public:
	// constructor initiliazes courseName with string supplied as argument
	GradeBook( string name )
	{
		setCourseName( name ); // call set function to initiliaze courseName
	} // end GradeBook constructor

	// function to set the course name
	void setCourseName( string name )
	{
		courseName = name; // store the course name in the object
	} // end function setCourseName

	// function to get the courseName
	string getCourseName()
	{
		return courseName; // returns object's courseName
	} // end function getCourseName

	// display a welcome message to the gradeBook user
	void displayMessage()
	{
			// call getCourseName to get the courseName
			cout << "Welcome to the gradebook for\n" ; getCourseName() 
				<< "1" << endl;
	} // end function displayMessage

private:
	string courseName; // course name for this GradeBook
}; //end class GradeBook

// function main begins program execution
int main()
{
	// create two GradeBook objects
	GradeBook gradeBook1( "CS Introduction to C++ Programming" );
	GradeBook gradeBook2( "CS102 Data Structures in C++" );

	// display initial value of courseName for each GradeBook
	cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
		<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
		<< endl;
} // end main

I'm using a "New Project" -> Win32 Console Apllication ->Application Type Console Application and "Add common header files for MFC".

cout << "Welcome to the gradebook for\n" ; getCourseName() there is a semicolon when there should be a <<. As far as i know there is not a <stream> header file. Why are you including it?

cout << "Welcome to the gradebook for\n" ; getCourseName() there is a semicolon when there should be a <<. As far as i know there is not a <stream> header file. Why are you including it?

Fixed the semicolon issue. But I still have the "<<" error messages. Any any idea what could be causing these? 2 of the 3 error messages mention "no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)" message. Lines 36 and 52. and line 35 has a message that says "IntelliSense: no operator "<<" matches these operands".

I removed the #include <stream>. No idea why it was there.

I can only imagine I forgot a header somewhere (I"m new to this), or something is in the wrong spot.

// Fig37.cpp :
#include <iostream>
#include "StdAfx.h"
using namespace std;

// GradeBook class definition
class GradeBook
{
public:

	GradeBook( string name )
	{
		setCourseName( name );
	}

	void setCourseName ( string name )
	{
		courseName = name;
	}

	string getCourseName()
	{
		return courseName;
	}

	void displayMessage()
	{

		cout << "Welcome to the grade book for\n" << getCourseName()
			<< "!" << endl;
	}
private:
	string courseName;
};

int main()
{

	GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
	GradeBook gradeBook2( "CS102 Date Structures in C++" );

	cout << "gradeBook1 created for course: "  << gradeBook1.getCourseName()
	   << "n\\gradeBook2 created for course: " << gradeBook2.getCourseName()
	   << endl;
}

for some reason, it just DOES NOT like the << operand. these are the only 4 error messages i get know. lines 29, 42, 30, and 43. what could be causing this? forgive me.....im very new.....

I get no errors when I compile --- at least after removing StdAfx.h header.

What compiler? What O/S?

StdAfx.h (precompiled header) must allways be included first!

Make sure you have <string> included in it or include it explicitly in your .cpp.

StdAfx.h (precompiled header) must allways be included first!

Make sure you have <string> included in it or include it explicitly in your .cpp.

i always include the stdafx.h, otherwise i get reminded to do so.

I'm using microsoft visual studio 2010 and Windows 7 Home Premium.

I believe I tried including

#include <string>

, but was asked why it was there so I removed it. I think it's in the first example of the code I posted. Although I spelled "include" wrong and wrote "inclide". I think I tried re-adding it with the correct spelling and got the same results, but I'll check again when I get home tonight. EDIT: Nevermind, I was including <stream> originally.

Thanks for the help guys. This is proving to a headache. A very fun headache, if that's possible, but I'm thoroughly enjoying it. If the suggestions work, I'll be sure to mark this as solved.

i always include the stdafx.h, otherwise i get reminded to do so.

By whom? I have *never* used it and my code works fine.

You need to #include <string>. The problem is because iostream declares the string class via some inclusions under-the-hood, but it does not include the << operator for the string. At least, on some implementations, this is what happens, on others, it includes both the string class and its << operator, and thus, making the code work just fine. So, if you use the string class, always #include <string>, even if you think it is not needed (because of secondary inclusions), or even if it happens to work without.

By whom? I have *never* used it and my code works fine.

VS 2010 won't compile until I include it. I get an error message saying something along the lines of "did you remember to include "stdfxa.h"? Once I add it, everything usually compiles fine. As for why you need it, I don't know. I'm a beginner. Maybe someone else can shed some light on the reason for needing this?

>> Maybe someone else can shed some light on the reason for needing this?
Just ask wikipedia. It's just an obscure Microsoft thing.

I had asked why you included <stream>. You should include <string> in your code.

Very firstly Your Syntax i.e.cout << "Welcome to the gradebook for\n" ; getCourseName()
<< "1" << endl;
is a wrong one, since you are putting a "semi-colon' before getCourseName(), that should be replaced with <<.
And Secondly <Stream> is not a specific header file.

commented: Read the thread before posting. -4

Also include <string>. ... i.e # include <string>

Yesterday:

I wrote first. I mean stdafx.h has to be the first thing to be included.

And make sure you include <string>.

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.