invalid conversion from `unsigned int' to `const char*'

hey guys....can anyone help me with this?
here is the full code...


#include "Student.h"
#include <fstream>//gia leitourgies eisodou eksodou se arxeia
#include <string>
#include <iostream>// parexei uposthriksh sto susthma eisodou/eksodou
#include <sstream>//to define several template classes that support
//iostreams operations on sequences stored in an allocated array object
#include <stdlib.h>//has got functions involving memory allocation, process control, conversions and others

using namespace std;

//Kataskeuasths
Student::Student(const string& id, const string& name, unsigned courses)
{ this -> id = "";
this -> name = "";
numOfcourses = courses;
grades = new float[numOfcourses];
cid = new string[numOfcourses];

for( int i = 0; i < courses; i++ ){
grades[i] = 0;
cid[i] = "";
}
}

//Kataskeuasths antigrafou
Student::Student(const Student& original)
{
numOfcourses=original.numOfcourses;
//desmeuetai mnhmh ston eleuthero xwro
grades = new float [numOfcourses];
cid = new string [numOfcourses];
//apodidetai h timh sth nea thesh mnhmhs
for(unsigned i=0;i<numOfcourses;i++)
{
grades[i]=original.grades[i];
cid[i]=original.cid[i];
}
}

//Katastrofeas
//diagrafoume o,ti exoume dhmiourgisei me new
Student::~Student()
{
// cout<<"deleting"<<endl;
delete []grades;
delete []cid;
}

//Apothikeuei sthn (i+1)-osth 8esh to (i+1)osto
//antika8istoume to id ths ekfwnhshs me ccode gia na mhn to mperdepsoume me to id tou foithth
void Student:: setCourse(unsigned i, const string& ccode)
{
cid[i+1] = ccode;
}

//Apothikeuei thn vathmologia sto (i+1)-osto ma8hma
void Student:: setGrade(unsigned i, float g)
{
grades[i+1]= g;
}

//Yperfortwsh telesth =
Student& Student::operator=(const Student& right)
{
if(this==&right) return *this;

//to right mporei na exei diko tou arithmo numOfcourses, allo grades kai cid
delete []grades;
delete []cid;

numOfcourses=right.numOfcourses;
grades=new float[numOfcourses];
cid= new string[numOfcourses];

for(unsigned i=0;i<numOfcourses;i++)
{
grades[i]=right.grades[i];
cid[i]=right.cid[i];
}
return *this;
}

float Student:: getGradeAvg() const
{ float sum=0;
unsigned perasmena=0;
float avg=0;
for(unsigned i=0; i<=numOfcourses; i++)
{ if (grades[i]>=5)
{sum = sum+grades[i];
perasmena++;
}
}//for
if (perasmena != 0)
{avg=sum/perasmena;}
else cout<<"O foithts den exei epityxei se kanena ma8hma, Mesos Oros=0"<<endl;
return avg;
}

//Yperfortwsh telesth <<
ostream& operator<<(ostream& out,const Student& s)
{
//stelnei sto out ton kwdiko tou foithth kai to onoma
out<<"<student id="""<<s.id<<""" name="""<<s.name<<""" courses="""<<s.numOfcourses<<"""\">"<<endl;
//stelnei sto out tous vathmous kai tous kwdikous stwn ma8hmatwn
for (unsigned i=0; i<=s.numOfcourses; i++)
{ out<<"<course grade="""<<s.grades[i]<<"""\">"<<" "<<s.cid[i]<<" </course>"<<endl;
}//for
out<<"</student>"<<endl;
//epistrefei sto programma to out
return out;
}


//Yperfortwsh telesth >>
istream& operator>>(istream& in,Student& s)
{
string word;
bool telos=false;
//oso diavazei lekseis apo to reuma in
while(in>>word && telos==false)
{
//an h leksh pou diavazei einai h "<student" tote apothikeueuei ena-ena ta xarakthristika tou foithth
if(word=="<student")
{
//paei sthn epomenh leksh h opoia einai to id="
in>>word;
//diaxwrizei tous xarakthres etsi wste na parei th leksh pou antistoixei sto id tou foithth
string str(word.begin()+4,word.end()-1);
s.id=str;

//paei sthn epomenh leksh h opoia einai to " name="
in>>word;
string str1(word.begin()+6,word.end()-1);
s.name=str1;

//paei sthn epomenh leksh h opoia einai to " courses="
in>>word;
string str2(word.begin()+9,word.end()-1);
//metatrepei to string se int me thn synarthsh atoi
unsigned number = atoi(str2.c_str());
s.numOfcourses=number;

Student s2(s.numOfcourses);
s=s2;
telos=true;
}
}

string pedio;
unsigned i=0;
while(in>>pedio && pedio!="</student>")
{
if(pedio=="<course")
{
in>>pedio;
string str3(pedio.begin()+7,pedio.end()-1);
double Gr = atof(str3.c_str());//PROSOXH!!!!!!!!!!! TO ATOI METATREPEI SE INTEGER KI EGW 8ELW FLOAT!!!!!!
s.grades[i] = Gr;

in>>pedio;
string str4(pedio.begin()+2,pedio.end()-2);
string Cid = pedio;
s.cid[i] = Cid;
i++;
}
}
return in;
}//Student.cpp
You haven't said what the problem is.
please use [ code ] [ /code ] tags, and tell us where the error occurs.
Also, would be nice if the comments were in english.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "Student.h"
#include <fstream>//gia leitourgies eisodou eksodou se arxeia
#include <string>
#include <iostream>// parexei uposthriksh sto susthma eisodou/eksodou
#include <sstream>//to define several template classes that support 
//iostreams operations on sequences stored in an allocated array object
#include <stdlib.h>//has got functions involving memory allocation, process control, conversions and others

using namespace std;

//Kataskeuasths
Student::Student(const string& id, const string& name, unsigned courses)
{ this -> id = "";
this -> name = "";
numOfcourses = courses;
grades = new float[numOfcourses];
cid = new string[numOfcourses];

for( int i = 0; i < courses; i++ ){
grades[i] = 0;
cid[i] = "";
}
}

//Kataskeuasths antigrafou
Student::Student(const Student& original)
{
numOfcourses=original.numOfcourses;
//desmeuetai mnhmh ston eleuthero xwro
grades = new float [numOfcourses];
cid = new string [numOfcourses]; 
//apodidetai h timh sth nea thesh mnhmhs
for(unsigned i=0;i<numOfcourses;i++)
{
grades[i]=original.grades[i];
cid[i]=original.cid[i];
}
}

//Katastrofeas
//diagrafoume o,ti exoume dhmiourgisei me new
Student::~Student()
{
// cout<<"deleting"<<endl;
delete []grades;
delete []cid;
}

//Apothikeuei sthn (i+1)-osth 8esh to (i+1)osto 
//antika8istoume to id ths ekfwnhshs me ccode gia na mhn to mperdepsoume me to id tou foithth
void Student:: setCourse(unsigned i, const string& ccode)
{
cid[i+1] = ccode;
}

//Apothikeuei thn vathmologia sto (i+1)-osto ma8hma
void Student:: setGrade(unsigned i, float g)
{
grades[i+1]= g;
}

//Yperfortwsh telesth =
Student& Student::operator=(const Student& right)
{
if(this==&right) return *this;

//to right mporei na exei diko tou arithmo numOfcourses, allo grades kai cid
delete []grades;
delete []cid;

numOfcourses=right.numOfcourses;
grades=new float[numOfcourses];
cid= new string[numOfcourses];

for(unsigned i=0;i<numOfcourses;i++)
{
grades[i]=right.grades[i];
cid[i]=right.cid[i];
}
return *this;
}

float Student:: getGradeAvg() const
{ float sum=0;
unsigned perasmena=0;
float avg=0;
for(unsigned i=0; i<=numOfcourses; i++)
{ if (grades[i]>=5)
{sum = sum+grades[i];
perasmena++;
}
}//for
if (perasmena != 0)
{avg=sum/perasmena;}
else cout<<"O foithts den exei epityxei se kanena ma8hma, Mesos Oros=0"<<endl;
return avg;
}

//Yperfortwsh telesth <<
ostream& operator<<(ostream& out,const Student& s)
{
//stelnei sto out ton kwdiko tou foithth kai to onoma
out<<"<student id="""<<s.id<<""" name="""<<s.name<<""" courses="""<<s.numOfcourses<<"""\">"<<endl;
//stelnei sto out tous vathmous kai tous kwdikous stwn ma8hmatwn
for (unsigned i=0; i<=s.numOfcourses; i++)
{ out<<"<course grade="""<<s.grades[i]<<"""\">"<<" "<<s.cid[i]<<" </course>"<<endl;
}//for
out<<"</student>"<<endl;
//epistrefei sto programma to out
return out;
}


//Yperfortwsh telesth >>
istream& operator>>(istream& in,Student& s)
{
string word;
bool telos=false;
//oso diavazei lekseis apo to reuma in
while(in>>word && telos==false)
{
//an h leksh pou diavazei einai h "<student" tote apothikeueuei ena-ena ta xarakthristika tou foithth
if(word=="<student")
{
//paei sthn epomenh leksh h opoia einai to id="
in>>word;
//diaxwrizei tous xarakthres etsi wste na parei th leksh pou antistoixei sto id tou foithth
string str(word.begin()+4,word.end()-1);
s.id=str;

//paei sthn epomenh leksh h opoia einai to " name="
in>>word;
string str1(word.begin()+6,word.end()-1);
s.name=str1;

//paei sthn epomenh leksh h opoia einai to " courses="
in>>word;
string str2(word.begin()+9,word.end()-1);
//metatrepei to string se int me thn synarthsh atoi
unsigned number = atoi(str2.c_str());
s.numOfcourses=number;

Student s2(s.numOfcourses);
s=s2;
telos=true;
}
}

string pedio;
unsigned i=0;
while(in>>pedio && pedio!="</student>")
{
if(pedio=="<course")
{
in>>pedio;
string str3(pedio.begin()+7,pedio.end()-1);
double Gr = atof(str3.c_str());//PROSOXH!!!!!!!!!!! TO ATOI METATREPEI SE INTEGER KI EGW 8ELW FLOAT!!!!!!
s.grades[i] = Gr;

in>>pedio;
string str4(pedio.begin()+2,pedio.end()-2);
string Cid = pedio;
s.cid[i] = Cid;
i++;	
}
}
return in;
}//Student.cpp 



well the problem occurs in line 143 and it says "invalid conversion from `unsigned int' to `const char*'"
I don't see why it gives you exactly that error message, but at line 143 you call the Student constructor Student(unsigned int) - And I don't see where you defined that one.
Topic archived. No new replies allowed.