Brlimjac
2022-06-24 03:09
采纳率: 50%
浏览 21

文件读取 this指针为空

所有程序可以正常运行 文件也可以正常写入打开 但再一次运行且程序涉及到数组就显示this指针为空(应该是读文件那一块有问题)
各位业界翘楚咋回事

img

#有关读文件
Manager::Manager()
{
ifstream ifsUser;
ifsUser.open(UserFILENAME, ios::in);

if (!ifsUser.is_open())
{
    this->m_UserNum = 0;
    this->m_UserArray = NULL;
    this->NowID ="0";
    this->m_UserFileIsEmpty = true;
    ifsUser.close();
    return;

}

char chUser;
ifsUser >> chUser;
if (ifsUser.eof())
{

    this->m_UserNum = 0;
    this->m_UserArray = NULL;
    this->NowID = "0";
    this->m_UserFileIsEmpty = true;
    ifsUser.close();
    return;

}
this->NowID = "0";
int numUser = this->get_UserNum();
this->m_UserNum = numUser;
this->m_UserArray = new User * [this->m_UserNum];
this->int_User();

}
int Manager::get_UserNum()
{
ifstream ifs;
ifs.open(UserFILENAME, ios::in);
string id;
string passwd;
int num = 0;
while (ifs >> id && ifs >> passwd)
{
num++;
}
return num;
}

void Manager::int_User()
{
ifstream ifs;
ifs.open(UserFILENAME, ios::in);
string id;
string passwd;

int index = 0;
while (ifs >> id && ifs >> passwd)
{
    User* US = NULL;

    this->m_UserArray[index] = US;
    index++;
}
ifs.close();

}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题