사용자가 입력 한 이름을 확인할 때까지 프로그램이 계속 작동합니다. 고객 정보로 가득 찬 파일에서 가져온 구조체 배열에서 검색하려는 이름을 입력하면 코어가 덤프 된 세그먼테이션 오류가 다시 발생합니다. 이 퍼즐.구조체에 액세스 할 때 세그먼트 오류
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
using namespace std;
struct AccountsDataBase{
char name[50];
string email;
long int phone;
string address;
};
#define MAX 80
AccountsDataBase * account = new AccountsDataBase[MAX];
void readIn(ifstream& file){
int i=0;
while(!file.eof()){
file >> account[i].name >> account[i].email >> account[i].phone >> account[i].address;
}
}
void getAccount(){
char userPick[50];
char streamName[50];
cout << " What account will we be using? " << endl;
cin.getline(streamName, 50);
for(int i=0; strcmp(account[i].name, streamName)!=0; i++){
if(strcmp(account[i].name, streamName)==0){
cout << "\n\n FOUND IT!! \n\n";
cout << account[i].name << "\n" << account[i].email << "\n" << account[i].phone << "\n" << account[i].address << endl;
}
}
}
int main(){
ifstream file;
file.open("2.dat"); //opens data account records text
readIn(file);
getAccount();
delete account;
return 0;
}
음 : 이제
count
가지고,이 같은 루프를 바꿀 수 있을까? – OldProgrammer@ 콜린 오류가 특정 라인을 나타내지 않는 한 라인 번호는 필요 없습니다. – yizzlez
@ 콜린 http://meta.stackexchange.com/questions/40164/should-we-close-fix-my-program-questions – sashoalm