2 Replies - 430 Views - Last Post: 10 April 2012 - 03:32 PM Rate Topic: -----

#1 Crusader175  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-March 12

Error C2679 in Code, why is this?

Posted 10 April 2012 - 01:44 PM

Here is the code. It is giving me the error inside of the void function. I don't know why but error C2679 is coming up which states that: "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'"


#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void EvaluateCholesterol (ofstream&, string);

int main()
{
	ofstream healthProfile;
	healthProfile.open("Profile.txt");
	string name= "Ryan D. Praskovich";
	for (int test= 1; test <=8; test++)
		EvaluateCholesterol (healthProfile, name);
	healthProfile.close();
	return 0;
}

void EvaluateCholesterol (ofstream& healthProfile, string name)
{
	int HDL;
	int LDL;
	cout<<  "Enter HDL for " << name << ": ";
	cin >> HDL;
	cout<<  "Enter LDL for " << name << ": ";
	cin >> LDL;
	float ratio= (float)HDL/(float)LDL;
	healthProfile << "Cholesterol Profile " << endl << "   HDL: " << HDL << "   LDL: " << LDL << endl << "   Ratio: " << fixed << setprecision(4) << ratio << endl;

	if (HDL < 40)
		healthProfile << "   HDL is too low" << endl;
	else if (HDL < 60)
		healthProfile << "   HDL is okay" << endl; 
	else 
		healthProfile << "   HDL is excellent" << endl;

	if (LDL < 100)
		healthProfile << "   LDL is optimal" << endl;
	else if (LDL < 130)
		healthProfile << "   LDL is near optimal" << endl;
	else if (LDL < 160)
		healthProfile << "   LDL is borderline high" << endl;
	else if (LDL < 190)
		healthProfile << "   LDL is high" << endl;
	else
		healthProfile << "   LDL is very high" << endl;

	if (ratio > 0.3)
		healthProfile << "   Ratio of HDL to LDL is good" << endl;
	else 
		healthProfile << "   Ratio of HDL to LDL is not good" << endl;
}



Thank you in advance

The error is on line 23 and 25 using cout

Is This A Good Question/Topic? 0
  • +

Replies To: Error C2679 in Code, why is this?

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4232
  • View blog
  • Posts: 13,287
  • Joined: 25-December 09

Re: Error C2679 in Code, why is this?

Posted 10 April 2012 - 01:53 PM

Where is your include file for the "string" class?

Jim
Was This Post Helpful? 1
  • +
  • -

#3 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

Re: Error C2679 in Code, why is this?

Posted 10 April 2012 - 03:32 PM

Indeed the problem is the missing include statement for the string class. Assuming that you're referring to std::string just add
#include <string>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1