列表< T> :: find':无法将参数1从'Student'转换为'int' [英] List<T>::find' : cannot convert parameter 1 from 'Student' to 'int'

查看:141
本文介绍了列表< T> :: find':无法将参数1从'Student'转换为'int'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  bool  InsertResult( char  * filename,List< Student> * list)
{
Student stu;
考试;

bool read = true ;
char stuid [ 10 ];

ifstream in ;
in .open(filename);

if (!in){
cout<< 文件无法打开。<< ENDL;
read = false ; // 在找不到文件时将读取设置为false
}

while (!in.eof())
{
int check = 1 ;
>> stuid;

for int i = 1 ; i< = list-> size(); i ++)
{
list-> get(i,stu);
if (strcmp(stu.id,stuid)== 0
{
check = 0 ;
break ;
}
}

>> exam.trimester;
>> exam.year;
>> exam.numOfSubjects;

for int i = 0 ; I< exam.numofsubjects;我++)>
{
in>> exam.sub [i] .subject_code;
in>> exam.sub [i] .subject_name;
in>> exam.sub [i] .credit_hours;
in>> exam.sub [i] .marks;
}

/// ////////// /////////////////////这里的问题////////////////////////// ///////
if (check == 0
{
if (list-> find(stu) - > item.exam-> empty())
{
list-> find(stu) - > item.exam = new 列表< exam> ;;
list-> find(stu) - > item.exam-> insert(exam);
}
else
list-> find(stu) - > item.exam-> insert(exam);
}

/// ////////// ////////////////////////////////////////////////// /////////////////
for int i = 1 ; i< = list-> size(); i ++)
{
list->得到(I,STU);
if (strcmp(stu.id,stuid)== 0
{
exam.calculateGPA();
stu.calculateCurrentCGPA();
list-> set(i,stu);
cout<< STU;
}
// cout<<考试;

}
}
in .close();
cout<< \ n \ t学生成绩已成功插入。\ n;
return true ;

}

解决方案

引用:

bool InsertResult(char * filename,List< s tudent> * list)



应该是

  bool  InsertResult( char  * filename,List<  S  tudent> * list)


尝试

 list-> find(atoi (stuid))



而不是

 list-> find(stu)


bool InsertResult(char *filename, List<Student> *list)
{
	Student stu;
	Exam exam;

	bool read=true;
	char stuid[10];

	ifstream in; 
	in.open(filename);

	if(!in){
		cout << "The file cannot open." << endl;
		read = false; //set the read to false when the file not found
	}
	
	while(!in.eof())
	{	
		int check=1;
		in >> stuid;

		for(int i=1; i<=list->size(); i++)
		{
			list->get(i,stu);
			if(strcmp(stu.id,stuid) == 0)
			{	
				check = 0;
				break;
			}
		}

		in >> exam.trimester;
		in >> exam.year;
		in >> exam.numOfSubjects;

		for(int i=0;i<exam.numofsubjects;i++)>
		{
			in>>exam.sub[i].subject_code;
			in>>exam.sub[i].subject_name;
			in>>exam.sub[i].credit_hours;
			in>>exam.sub[i].marks;
		}

//////////////////////////////////Problem in here /////////////////////////////////
		if (check==0)
		{
			if(list->find(stu)->item.exam->empty())
			{
			list->find(stu)->item.exam = new List<exam>;
				list->find(stu)->item.exam->insert(exam);
			}	
			else
				list->find(stu)->item.exam->insert(exam);						
		}
	
////////////////////////////////////////////////////////////////////////////////
		for(int i=1; i<=list->size(); i++)
		{
			list->get(i,stu);
			if(strcmp(stu.id,stuid) == 0)
			{	
				exam.calculateGPA();
				stu.calculateCurrentCGPA();
				list->set(i,stu); 
				cout << stu;
			} 
				//cout << exam;

		}
	}
	in.close();
	cout << "\n\t Student results are successfully inserted.\n";
	return true;

}

解决方案

Quote:

bool InsertResult(char *filename, List<student> *list)


That should be

bool InsertResult(char *filename, List<Student> *list)


Try

list->find(atoi(stuid))


instead of

list->find(stu)


这篇关于列表&lt; T&gt; :: find':无法将参数1从'Student'转换为'int'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆