텍스트 파일에서 티켓을 검색 할 코드를 작성 중입니다. 각 티켓은 "***"로 시작하고 "###"로 끝납니다.특정 필드에서 키워드 검색 후 텍스트 파일에서 여러 레코드 추출
(1) "도시"필드에서 사용자 입력에서 키워드를 검색하십시오. (2) 발견 된 레코드에서 모든 레코드와 라인을 반환합니다.
기록은 다음과 같습니다
***
Ticket Number :
First Name : T
First Name : C
Address of Violations : 123 Malberry Ln.
City : Oak Park //Need user to input City and Pull all tickets from that City
Plate : Q1234
Vin Number : V1234
Violation Narrative : NO PARKING
Violation Code :V1234
Violation Amount :50
Late Fee : 100
Make :
Model :
Was this Paid ? : 0
Date : 1012017
Time : 1200
Pay by Date : 1012018
Officer Number : 6630
###
내 쿼리가 각 범주에 대해 구체적으로해야합니다.
예를 들어, 세 개의 레코드가 있고 두 개가 같은 도시 "Oak Park"의 레코드 인 경우 두 개의 "Oak Park"레코드를 표시해야합니다. 나는이 문제를 해결하기 위해 시작 했어 아마도 이런을 "###" "***"에서 기록을 끌어 검색을하고 어떻게
:
{
ifstream in("tickets.txt");
string beforeEqual = "";
string afterEqual = "";
while (!in.eof())
{
getline(in, beforeEqual, '***'); //grtting string upto =
getline(in, afterEqual, '###'); //getting string after =
cout << afterEqual << endl; //printing string after =
}
그러나 나는 또한 통합해야 ("City :"+ search_token)을 검색하십시오.
그래서 (City Search) 할 때 그 도시에서 모든 티켓을 가져옵니다.
어떻게 구현 될까요? 올바른 방향으로 가고 있습니까?
내 작품은 지금까지 그냥 일반적인 검색 :
void city_search() {
string search;
string line;
ifstream inFile;
inFile.open("tickets.txt");
if (!inFile) {
cout << "Unable to open file" << endl;
exit(1);
}
cout << "Please enter a plate Number to search : " << endl;
cin >> search;
size_t pos;
while (inFile.good())
{
getline(inFile, line); // get line from file
pos = line.find(search); // search
if (pos != string::npos) // string::npos is returned if string is not found
{
cout << search << "Found!";
break;
}
}
"내 검색어는 각 카테고리에 따라 달라야합니다." - 카테고리별로 티켓 번호, 이름, 접시, 도시 등을 의미합니까? –
@ JackOfBlades. City에 대한 함수 호출을 다른 범주로 복제 할 것입니다. 나는 이미이 함수들을 호출하는 working switch 문을 가지고있다. –