help fast plz

no matching function for call to 'student::set(std::istream&, std::string&, char[50], int&)'

error is the line after the arrow ( -> )
----------------------------------------

char studentName[50];
int nCourses;
string sID;

inFile >> nCourses >> sID;
inFile.getline(studentName, 50);

-> someStudent.set(inFile, sID, studentName, nCourses);




here is the set function:-
--------------------------

void student::set(fstream& w, string x, string y, int z)
{
int i;

ID = x;
name = y;
numberOfCourses = z;

for(i = 0; i < 10; i++)
{
w >> coursesTaken[i].code >> coursesTaken[i].title
>> coursesTaken[i].credit >> coursesTaken[i].mark;
}
}

here is the class:-
-------------------
class student
{
private:
string ID, name;
int numberOfCourses;
double GPA;
Courses coursesTaken[10];

public:

void set(fstream& , string , string , int);
double getGPA()const;
void calculateGPA();
void print()const;
student();
student(fstream& , string, string, int);

};


plz help as fast as possible.
You told the function "student::set()" to expect an std::string as the third argument. So the variable that you pass it should be of type std::string, not a pointer to a c-string array.
Last edited on
but doesnt the compiler read an array of characters as a string??
Yes it should, but that error shows some other odd things as well so I suspect that you're not posting your actual code. Why don't you copy and paste what code you have, and put them between the code brackets this time, so that we can see what is going on.
ill give you the whole program...

--------------------------------------------------

(main file)

#include "Student.h"

int main()
{
ifstream inFile;
inFile.open("courses.txt");

student someStudent;
char studentName[50];
int nCourses;
string sID, Name;

inFile >> nCourses >> sID;
inFile.getline(studentName, 50);

someStudent.set(inFile, sID, studentName, nCourses);
someStudent.calculateGPA();
someStudent.print();

inFile.close();
return 0;
}
-------------------------------------------------------------------------

(implemented file)

#include "Student.h"

void student::set(fstream& w, string x, string y, int z)
{
int i = 0;

ID.assign(x);
name.assign(y);
numberOfCourses = z;

while(i < 10)
{
w >> coursesTaken[i].code >> coursesTaken[i].title
>> coursesTaken[i].credit >> coursesTaken[i].mark;

i+= 1;
}
}
void student::calculateGPA()
{
int k;
int totHours;
double totMark;

while(k < 10)
{
totHours = totHours + coursesTaken[k].credit;

if(coursesTaken[k].mark > 90)
{
coursesTaken[k].mark = 4.00;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 85)
{
coursesTaken[k].mark = 3.33;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 80)
{
coursesTaken[k].mark = 3.00;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 75)
{
coursesTaken[k].mark = 2.30;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 70)
{
coursesTaken[k].mark = 2.00;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 65)
{
coursesTaken[k].mark = 1.30;
totMark = coursesTaken[k].mark + totMark;
}
else if(coursesTaken[k].mark > 60)
{
coursesTaken[k].mark = 1.00;
totMark = coursesTaken[k].mark + totMark;
}
else
{
coursesTaken[k].mark = 0.00;
totMark = coursesTaken[k].mark + totMark;
}
k+=1;
}
GPA = totMark/totHours;
}
double student::getGPA()const
{
return GPA;
}
void student::print()const
{
cout<<ID<<" "<<name<<" "<<"has GPA = "<<GPA << "\n";
}
student::student()
{
fstream w;
ID;
name;
numberOfCourses = 0;
}
student::student(fstream& w, string x, string y, int z)
{
set(w,x,y,z);
}
--------------------------------------------------------------------------------

(header file)

#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>

using namespace std;

struct Courses
{
string code, title;
int credit, mark;
};

class student
{
private:
string ID, name;
int numberOfCourses;
double GPA;
Courses coursesTaken[10];

public:

void set(fstream& , string , string , int);
double getGPA()const;
void calculateGPA();
void print()const;
student();
student(fstream& , string, string, int);

};

#endif // STUDENT_H_INCLUDED
There it is, an 'std::ifstream' is not the same thing as an 'std::fstream'. I should have asked for the whole error code, it's just one of those days I suppose. You have to pick on or the other to work with.

Also, why are you mixing and matching double and int? That's bound to cause you some trouble.
So what should i write instead?

I mixed them because the numbers im getting from the file are integers and i want to convert them to double by dividing double by integer.
Never mind i have fixed the problem :D

Thank you alllllllllllot man u dont know how much trouble this thing gave me.........been trying to fix it for a whole damn week XD
To be honest I only saw the warnings and didn't actually look at that part of the code. As long as you know for a fact that information isn't being lost in the type conversion then don't worry about it.
Well I am getting wrong numbers but i dont think its caused by the mix of int and double.

but thanx allot for your efforts sir...........really apreciate it :D
Topic archived. No new replies allowed.