Could someone please help me or point/explain to me why the error in
line 46 ?
////////////////////////Error message:////////////////////////////////
bash-2.05b$ g++ test3.cpp
test3.cpp: In function `int main()':
test3.cpp:46: error: request for member `print_data' in `ptrstudent',
which is
of non-aggregate type `Record_info*'
//////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX=50;
typedef double Number;
class Record_info {
public:
string bypassed;
string name;
int midterm;
Number quiz;
//double quiz;
Number final;
string testname;
void print_data();
};
void Record_info:: print_data(){
cout <<"name is : "<<name<<en dl;
cout <<"Midterm is : "<<midterm<<end l;
cout <<"Quiz is : "<<quiz<<en dl;
cout <<"Final is : "<<final<<e ndl;
cout <<"Testname is : "<<testname<<en dl;
}
int main (void){
Record_info student[MAX],*ptrstudent;
ptrstudent = student;
ifstream in ("test2.txt" );
string line;
string line2;
char buffer[40];
while (getline(in,lin e)){
if (line.find("#") !=string::npos) continue ;
istringstream stringstreams(l ine);
stringstreams>> ptrstudent->bypassed>>ptrs tudent->name>>ptrstude nt->midterm;
stringstreams>> ptrstudent->quiz>>ptrstude nt->final>>ptrstud ent->testname;
ptrstudent++;
}
for (ptrstudent=stu dent; ptrstudent->midterm;ptrstu dent++){
if (ptrstudent->bypassed.find( "Y")!=string::n pos)continue ;
double test= ptrstudent->quiz +100;
cout << "test is : "<<test<<en dl;
ptrstudent.prin t_data(); //line 46
stringstream stream,stream2;
stream << "Do Add Bonus: "<<ptrstude nt->name <<" "
<<ptrstudent->quiz;
string task(stream.str ());
cout << task << endl;
stream2 <<"Do ExtraCredit: "<<ptrstude nt->name<<" :"
<<ptrstudent->final<< " has done extra credit " <<ptrstudent->final+5;
string task2(stream2.s tr());
cout <<task2<<endl ;
}
return 0;
}
//////////////////////////input file:
test2.txt//////////////////////////
###
Y Tony 90 -15.2 98.2 math
N Michael 95 17.2 92.2 physics
N Amy 82 13.9 78.2 accounting
line 46 ?
////////////////////////Error message:////////////////////////////////
bash-2.05b$ g++ test3.cpp
test3.cpp: In function `int main()':
test3.cpp:46: error: request for member `print_data' in `ptrstudent',
which is
of non-aggregate type `Record_info*'
//////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX=50;
typedef double Number;
class Record_info {
public:
string bypassed;
string name;
int midterm;
Number quiz;
//double quiz;
Number final;
string testname;
void print_data();
};
void Record_info:: print_data(){
cout <<"name is : "<<name<<en dl;
cout <<"Midterm is : "<<midterm<<end l;
cout <<"Quiz is : "<<quiz<<en dl;
cout <<"Final is : "<<final<<e ndl;
cout <<"Testname is : "<<testname<<en dl;
}
int main (void){
Record_info student[MAX],*ptrstudent;
ptrstudent = student;
ifstream in ("test2.txt" );
string line;
string line2;
char buffer[40];
while (getline(in,lin e)){
if (line.find("#") !=string::npos) continue ;
istringstream stringstreams(l ine);
stringstreams>> ptrstudent->bypassed>>ptrs tudent->name>>ptrstude nt->midterm;
stringstreams>> ptrstudent->quiz>>ptrstude nt->final>>ptrstud ent->testname;
ptrstudent++;
}
for (ptrstudent=stu dent; ptrstudent->midterm;ptrstu dent++){
if (ptrstudent->bypassed.find( "Y")!=string::n pos)continue ;
double test= ptrstudent->quiz +100;
cout << "test is : "<<test<<en dl;
ptrstudent.prin t_data(); //line 46
stringstream stream,stream2;
stream << "Do Add Bonus: "<<ptrstude nt->name <<" "
<<ptrstudent->quiz;
string task(stream.str ());
cout << task << endl;
stream2 <<"Do ExtraCredit: "<<ptrstude nt->name<<" :"
<<ptrstudent->final<< " has done extra credit " <<ptrstudent->final+5;
string task2(stream2.s tr());
cout <<task2<<endl ;
}
return 0;
}
//////////////////////////input file:
test2.txt//////////////////////////
###
Y Tony 90 -15.2 98.2 math
N Michael 95 17.2 92.2 physics
N Amy 82 13.9 78.2 accounting
Comment