C++简单程序 最快的我给分(下面程序怎么按0不跳出结束啊!)

来源:百度知道 编辑:UC知道 时间:2024/05/25 14:13:36
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
#define NULL 0

class Student
{
public:
char name[32];
float sorcer;
Student *next;

};

Student *head =NULL;
bool check(string str)
{
for (int i=0;i<str.length();i++)
{
if (str[i]<'0'||str[i]>'9'&&str[i]!='.')
{
return false;
}
}
return true;

}
Student *creat()
{
Student *p1,*p2;
p1=new Student;
head =p1;
p2=p1;
cout <<"请输入你要创建的学生姓名(请用0来结束创建):";
cin>>p1->name;

if (p1->name!=0)
{
cout <<"请输入他/她的成绩:";
string str;
cin >>str;
while (!check(str))
{
cout <<" 请重新输入数字,其他字符错误:" <<endl;
cin >>str;
}

把所有的p1->name!=0改成p1->name[0] != '0'

由于p1->name被定义成char型,所以输入的数据会被转为字符型,
所以不能直接判断0,
而是需要这么判断:
*(p1->name)!='0'