我正在尝试创建一个读取银行客户端用户输入的程序。信息存储在结构向量中,但每当我尝试调用特定值,即客户端[0] .name,在读取用户的菜单选项后,客户端[0] .name的值被清除
以下是我从文件中读取值的方法:
bool startUp::readFile() {
ifstream inStreamS, inStreamC, inStreamA;
string line, line2;
inStreamS.open("staff.txt");
inStreamC.open("client-info.txt");
inStreamA.open("account-info.txt");
if (inStreamS.fail() || inStreamC.fail() || inStreamA.fail()) {
cout << "File Open Failure." << endl;
return false;
}
while (inStreamS >> e.userID >> e.pass >> e.role) {
employee.push_back(e);
}
inStreamS.close();
int x = 0;
int q = 0;
while (getline(inStreamC, line)) {
switch (x) {
case 0:
c.name = line;
x++;
getline(inStreamA, line2);
c.accNum = line2;
q++;
break;
case 1:
c.address = line;
x++;
getline(inStreamA, line2);
c.accType = line2;
q++;
break;
case 2:
c.social = line;
x++;
getline(inStreamA, line2);
c.accBal = line2;
q = 0;
break;
case 3:
c.employer = line;
x++;
break;
case 4:
c.income = line;
x = 0;
client.push_back(c);
break;
default:
cout << "Something Broke While Trying To Read The Client File."
<< endl;
break;
}
/*c.name = line;
getline(inStreamC, line);
c.address = line;
getline(inStreamC, line);
c.social = line;
getline(inStreamC, line);
c.employer = line;
getline(inStreamC, line);
c.income = line;
while (getline(inStreamA, line2)) {
c.accNum = line2;
getline(inStreamA, line2);
c.accType = line2;
getline(inStreamA, line2);
c.accBal = line2;
client.push_back(c);
}*/
}
inStreamC.close();
inStreamA.close();
return true;
}
这是.txt文件,每行是一个不同的变量,每个客户5行:
test1
test1 test1
123456789
test1 t
1234
test2
test2 test2
234567890
test2 t
5678
这是我的结构:
struct Clients {
string name, address, social, employer, income, accNum, accType, accBal;
};
这就是我失去价值的地方:
void CAM::runCAM() {
system("clear");
cout << "\t============================================================" <<
endl;
cout << "\t| Teller Terminal System - Client And Account Management |" <<
endl;
cout << "\t============================================================" <<
endl;
cout << "[1] Add A Client" << endl;
cout << "[2] Add An Account" << endl;
cout << "[3] Edit Client Information" << endl;
cout << "[4] Manage An Account" << endl;
cout << "[5] Save Client And Account Information" << endl;
cout << "[6] Exit" << endl;
cout << "Please Choose An Option: ";
cin >> uI;
checkInput(uI);
switch (check) {
case '1':
system("clear");
cout << "A New Client Will Be Added, Please Provide The Following: "
<< endl;
cin.clear();
cin.ignore(10000, '\n');
cout << "\n" << client[0].name;
addClient();
break;
case '2':
system("clear");
addAccount();
break;
case '3':
system("clear");
cout << "\n" << client[0].name;
cin.clear();
cin.ignore(10000, '\n');
editClient();
break;
在案例3中,不再打印该值,但它将在该实例之前的任何位置。