小白求助C++问题,在线等

void StudentList::DeleteStudent(string s)
{
vector ::iterator p1;
p1=stuArr.begin();
if (stuArr.size()==0)
{
cout<<"当前列表没有元素可以删除"< }
else
{
while (p1!=stuArr.end())
{
if(p1->GetName()=s)
{
stuArr.erase(p1);
}
}
}
}

编译C:\Documents and Settings\Administrator\桌面\实验9\实验9\StudentList.cpp(27) : error C2451: conditional expression of type 'class std::basic_string,class std::allocator >' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

StudentList.obj - 1 error(s), 0 warning(s)

cout 末尾多一个<
if(p1->GetName()=s) 这个是==吧
if以后,若不等,p1没有指向下一个,while可能是死循环

cout<<"当前列表没有元素可以删除"< 改成 cout<<"当前列表没有元素可以删除"<<endl;

cout后没要有分号,第二个if判断的是“==”。

p1->GetName()=s,这条语句有问题!条件判断,“=”和“==”是常出现的一个错误,如果你的s仅仅是作为一个判断常量,那么请把其声明为只读常量,然后写在左边,这样可以方便检查。

cout末尾处的<改成;

参观西湖说的很对!
cout 末尾多一个<,少了一个分号;
if(p1->GetName()=s) 这个是==吧
if以后,若不等,p1没有指向下一个,while可能是死循环,要有p1++

参观西湖说的很对!
cout 末尾多一个<,少了一个分号;
if(p1->GetName()=s) 这个是==吧
if以后,若不等,p1没有指向下一个,while可能是死循环,要有p1++

参观西湖说的很对!+1

cout 末尾多一个<,要是换行就再加一个,要不就删掉。
if(p1->GetName()=s) 这个是==吧,或者用equals进行比较,可以试试看

void StudentList::DeleteStudent(string s)
{
vector ::iterator p1;//这里的vector后面应该加上 <类型名>
p1=stuArr.begin();
if (stuArr.size()==0)
{
cout<<"当前列表没有元素可以删除"; }
else
{
while (p1!=stuArr.end())
{
if(p1->GetName()=s)
{
stuArr.erase(p1);
}
else
{
iter++;
}
}
}
}