想在function.cpp中创建一个类数组来接收user.cpp读出的文件,但是一直报错,那位可以解决一下
#pragma once
#include<iostream>
using namespace std;
#include"user.cpp"
#include<fstream>
#include<conio.h>
#include<string>
#define file "user.txt"
class function {
public:
function() {
}
void adduser() {//开户
fstream fs;
int numuser = 0;
fs.open(file, ios::in);
while ( fs>>id && fs >> Name && fs >> password && fs>>Money && fs>>State ){
++numuser;
}
cout << "总人数为" << numuser<<endl;
fs.close();
fs.open(file, ios::app | ios::out);
cout << "你的账号为:" << Id + numuser << endl;
cout << "请输入姓名" << endl;
cin >> Name;
string Password1;
string Password2;
cout << "请输入长度50以内的密码并按回车键确定" << endl;
//密码输入
char ch;
while ((ch = _getch()) != 13)
{
Password1 += ch;
cout << "*";
}
cout << endl << "请再次输入以确定密码并按回车键确定" << endl;
while ((ch = _getch()) != 13)
{
Password2 += ch;
cout << "*";
}
if (Password2 == Password1) {
cout << "密码正确" << endl;
}
else {
cout << "密码错误" << endl;
system("pause");
}
cout << "输入充值的金额" << endl;
cin >> Money;
fs << Id + numuser << " "//账号
<< Name << " " //姓名
<< Password2 << " "//密码
<< Money << " "//余额
<< State << endl;//状态
fs.close();
}
void frozen() {
cout << "请输入需要挂失的账号:"<<endl;
int account;
cin >> account;
function** cgstate = user.getdata(account);//报错的地方,,,
}
string Name;
int Id = 10000;
int id;
int Money = 0;
int State = 1;
string password;
};
#pragma once
#include<iostream>
using namespace std;
#include<string>
#define file "user.txt"
#include<fstream>
class user {
friend class function;
public:
user( int id, string name, string password, int money,int State) {
this->Name = name;
this->id = id;
this->Password = password;
this->State = State;
}
user** getdata(int account) {//获取文档信息
fstream ofs;
int i = 0;
int nume = 0;
ofs.open(file, ios::in);
while (ofs >> id && ofs >> Name && ofs >> Password && ofs >> money && ofs >> State) {
nume++;//总人数
}
arry[nume];
while (ofs >>id && ofs >> Name && ofs >>Password && ofs >> money && ofs >> State) {
user* User = NULL;
User = new user(id, Name, Password, money, State);
arry[i] = User;
i++;
}
ofs.close();
return arry;
}
string Name;
int id;
string Password;
int money;
int State;
user* arry[];
~user() {
delete this->arry;
}
};