我想将信息放入文件中的数组中。 但是,i1File上有错误。 i1File中的值是人员的姓名。 我想将值放在I1File的stna排列中。 i2File中的值为1或2。 我想以stngn格式将值放在I2File中。 输入函数中发生错误。
#include <iostream>
#include <stdlib.h>
#include<string>
#include <fstream>
#include <time.h>
#include<windows.h>
#include <mmsystem.h>
using namespace std;
#pragma comment(lib, "winmm.lib")
#define MAX_SIZE 1000
class seat {
string stna[100]; // 학생들이름
int stgn[100] = { 0, }; //학생들 성별
int inputint;
string inputString;
//char inputString[MAX_SIZE];
public:
int numbern = 0;// 학생수
void inputinformation(void);
void mainchang(void);
void setseat(void);
void zolottery(void);
void danglottery(void);
void checkrecord(void);
void setmember(void);
};
void seat::mainchang()
{
cout << "┌─────────────────────── 채 메인 화면 ────────────────────────┐" << endl;
cout << "│ │" << endl;
cout << "│ │" << endl;
cout << "│ 1.자리 배치 │" << endl;
cout << "│ │" << endl;
cout << "│ 2.조 추첨 │" << endl;
cout << "│ │" << endl;
cout << "│ 3.당번 추첨 │" << endl;
cout << "│ │" << endl;
cout << "│ 4.회원 설정 │" << endl;
cout << "│ │" << endl;
cout << "│ 5.기록 확인 │" << endl;
cout << "│ │" << endl;
cout << "│ 6.회원 설정 │" << endl;
cout << "│ │" << endl;
cout << "│ 7.종 료 │" << endl;
cout << "│ │" << endl;
cout << "└─────────────────────────────────────────────────────────────┘" << endl;
}
void seat::setseat() {
};
void seat::zolottery() {
system("cls");
int zonumber;
cout << "조 인원은 몇명입니까?" << endl;
cin >> zonumber;
};
void seat::checkrecord() {};
void seat::danglottery() {
system("cls");
cout << "당번 추첨 중입니다. □ □ □ □ □..." << endl;
Sleep(300);
system("cls");
cout << "당번 추첨 중입니다. ■ □ □ □ □.." << endl ;
Sleep(300);
system("cls");
cout << "당번 추첨 중입니다. ■ ■ □ □ □...." << endl ;
Sleep(300);
system("cls");
cout << "당번 추첨 중입니다. ■ ■ ■ □ □.." << endl ;
Sleep(300);
system("cls");
cout << "당번 추첨 중입니다. ■ ■ ■ ■ □..." << endl ;
Sleep(300);
system("cls");
cout << "당번 추첨 중입니다. ■ ■ ■ ■ ■" << endl ;
Sleep(200);
system("cls");
int r = 0;
srand(time(NULL));
r = rand() % numbern + 1;
ifstream nuFile("number.txt");
for (int i = 0; i < numbern; i++) {
nuFile.getline(inputString, 100);
if (i + 1 == r) {
system("cls");
PlaySound("환영드럼.wav", NULL, SND_ASYNC | SND_LOOP);
cout << "┌─────────────────── 추첨 결과 ───────────────────┐" << endl;
cout << "│ "<<inputString << "님이 당첨되었습니다" << " │" <<endl;
cout << "└─────────────────────────────────────────────────┘" << endl;
Sleep(2600);
PlaySound(0, 0, 0);
Sleep(1000);
nuFile.close();
break;
}
}
};
void seat::inputinformation(void) {
ifstream i1File("number.txt");
ifstream i2File("gender.txt");
int n = 0;
while (!i1File.eof() && !i2File.eof()) {
i1File.getline(inputString, 100);
stna[n] = inputString;
i2File.getline(inputint, 100);
stgn[n] = inputint;
n++;
}
for (int i = 0; i < numbern; i++) {
cout << stna[i] << ", " << stgn[i];
}
system("cls");
Sleep(10000);
//stna[100][100]; // 학생들이름
//stgn[100][1]; //학생들 성별
}
void seat::setmember(void) {
system("cls");
int input;
cout << "┌─────────────────────── 채 설정 화면 ────────────────────────┐" << endl;
cout << "│ │" << endl;
cout << "│ │" << endl;
cout << "│ 1.이름 설정 │" << endl;
cout << "│ │" << endl;
cout << "│ 2.성별 설정 │" << endl;
cout << "│ │" << endl;
cout << "│ │" << endl;
cout << "└─────────────────────────────────────────────────────────────┘" << endl;
cout << "원하시는 선택지를 선택해주세요. ";
cin >> input;
system("cls");
if (input == 1) {
string name;
system("cls");
cout << "학생수를 입력해주세요.";
cin >> numbern;
ofstream outFile("number.txt");
system("cls");
for (int i = 0; i < numbern; i++) {
cout << i + 1 << "번째 사람의 성함을 입력해주세요" << endl;
cout << "이름: ";
cin >> name;
outFile << name << endl;
system("cls");
}
outFile.close();
}
else if (input == 2) {
int gender;
system("cls");
ofstream outFile("gender.txt");
ifstream inFile("number.txt");
system("cls");
for (int i = 0; i < numbern; i++) {
inFile.getline(inputString, 100);
cout << inputString << "님의 성별을 입력해주세요.(남자 = 0 여자 = 1)" << endl;
cout << "성별: ";
cin >> gender;
outFile << gender << endl;
system("cls");
}
inFile.close();
outFile.close();
inputinformation();
}
}
class student {
public:
int gender; // 0남자 1여자
int seatnumber; //고정 번호 // 없으면 0
};
int main(void) {
seat seat;
while (1) {
again:
int input, snsn;
seat.mainchang();
cout << "학생들의 수를 입력해주세요.";
cin >> snsn;
seat.numbern = snsn;`enter code here`
cout << "원하시는 선택지를 선택해주세요. ";
cin >> input;
if (input == 1) seat.setseat();
else if (input == 2) seat.zolottery();
else if (input == 3) seat.danglottery();
else if (input == 4) seat.setmember();
else if (input == 5) seat.checkrecord();
else if (input == 6) seat.setmember();
else if (input == 7) break;
else {
system("cls");
cout << "다시 입력해주세요";
goto again;
}
seat.mainchang();
system("cls");
}
}
接收数组中文件中的所有信息。