Я изо всех сил пытаюсь понять, что мне нужно сделать, чтобы получить доступ к массивам, созданным в написанных мной функциях. Мне нужен доступ к нему, чтобы я мог перейти к следующей части задания, над которым я работаю. В коде я могу перечислить команды, ввести название команды и получить информацию о том, сколько раз они выиграли, но я не могу получить доступ к массивам, созданным из текстовых файлов, чтобы создать новую функцию, которая затем сравнивает массивы. Код ниже. Любые идеи?
#include <fstream>
#include <string>
using namespace std;
//Function prototypes
void wonOnceList(string[], int&);
void teamWinsList(string, string[], int&);
int main()
{
string teamNameEntered;
const int ARRAY_SIZE = 100; // Array size
string teamName[ARRAY_SIZE]; // Array with team names that have won at least once
string worldSeriesWinnersList[ARRAY_SIZE]; //list of winning teams from 1903 to 2012
wonOnceList(teamName[], ARRAY_SIZE);
cout << "\nEnter the name of one of the teams listed above to find out the number\n";
cout << "of times that team has won the World Series from 1903 to 2012." << endl;
getline(cin, teamNameEntered);
cout << "You entered " << teamNameEntered << endl;
teamWinsList(teamNameEntered);
return 0;
}
void wonOnceList(string teamName, int& count) {
const int ARRAY_SIZE = 100; // Array size
string teamName[ARRAY_SIZE]; // Array with 100 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object
inputFile.open("Teams.txt"); // Open the file.
// Read the team names from the file into the array.
while (count < ARRAY_SIZE && getline(inputFile, teamName[count]))
count++;
// Close the file.
inputFile.close();
// Display the teams read.
cout << "The teams that have won the World Series: \n";
for (int index = 0; index < count; index++)
cout << teamName[index] << endl;
}
void teamWinsList(string winners, string worldSeriesWinnersList[], int& ARRAY_SIZE) {
int timesWon = 0; //wins counter
const int ARRAY_SIZE = 100; // Array size
string worldSeriesWinnersList[ARRAY_SIZE]; // Array with 100 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object
inputFile.open("WorldSeriesWinners.txt"); // Open the file.
// Read the team names from the file into the array.
while (count < ARRAY_SIZE && getline(inputFile, worldSeriesWinnersList[count]))
count++;
// Close the file.
inputFile.close();
//loop determining wins per team
for (int i = 0; i < ARRAY_SIZE; i++) {
if (winners == worldSeriesWinnersList[i])
timesWon++;
}
//outputing times won per team
cout << "\nThe team " << winners << " has won the World Series ";
cout << timesWon << " times from 1903 to 2012." << endl;
}```