클래스를 쓰고 백터를 활용해서..
야구선수 데이터로 팀이름으로 검색하면 팀이름선수정보 다나오게하기
이름으로 찾으면 그선수에 대한 정보 나오게 하기
이렇게 검색할수 있게해야되는데
현재 시작부터 잘 안되네요;
데이터 파일을 불러올 함수를 만드는중인데
istream& operator>>( istream& in, Player& player)
이 함수 부분에서 컴파일 하면 자꾸 temp 랑 data 가 선언이 안되어있다고 하고..
info data 도 안먹히네요;
데이터는 대략 이런식 입니다
--------------------------------------------------------
팀 선수 배트 히트 더블 트리플 홈런 (이순서예요;)
--------------------------------------------------------
BAL Jay Payton 338 82 10 2 7
FLA Chris Volstad 26 3 2 0 0
BOS Jason Varitek 423 93 20 0 13
BOS J.D. Drew 368 103 23 4 19
STL Chris Carpenter 5 0 0 0 0
CHW Paul Konerko 438 105 19 1 22
COL Jason Hirsh 4 0 0 0 0
MIL Mike Rivera 62 19 5 0 1
--------------------------------------------------------
이건 제가 지금 쓴 코드구요;
위에서말한 선언안되있다는 부분이랑
그 데이터파일로 어떻게 팀이름 치면 팀 선수 다나오게하고 그런것도 좀
설명과 해결방법좀 도와주셨으면 합니다 ㅠㅠ
#ifndef PLAYER_
#define PLAYER_
using namespace std;
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
class Player
{
public:
Player();
struct info
{
char team[3];
char name[20];
int bats;
int hits;
int doubles;
int triples;
int homeruns;
double batAve;
double slugPct;
};
vector<info> data;
};
ostream& operator<<( ostream& out, const Player& player);
istream& operator>>( istream& in, Player& player);
/*--------------------------------------------------------------------------
Name: operator>>
Purpose:
Receive:
Return:
-------------------------------------------------------------------------*/
istream& operator>>( istream& in, Player& player)
{
ifstream InStream;
string InFile;
cin>>InFile;
InStream.open( InFile.c_str(), ios::in );
info temp;
if (InStream.fail())
{
cerr<<"\n*** Unable to read from '"<<InFile<<"' ***\n\n";
exit( 1 );
}
else
{
while (!InStream.eof())
{
InStream>>temp.team;
InStream>>temp.name;
InStream>>temp.bats;
InStream>>temp.hits;
InStream>>temp.doubles;
InStream>>temp.triples;
InStream>>temp.homeruns;
InStream>>temp.batAve;
data.push_back(temp);
}
}
return in;
}
#endif
제가 하고있는 과제 출처는 여깁니다..
http://www.cse.msu.edu/~cse232/Projects/project10