I am trying to return a vector with template T with data from a file to be searched through in another function.
The program I am working on is a program that stores the name, date of birth, and address that was inputted to the program. I have tried to store the returned vector in another vector with the template type but it keeps on showing:
Error C2672 'getDataToVector': no matching overloaded function found
Error C2783 'std::vector> getDataToVector(std::ifstream)': could not deduce template argument for 'T'
template <class T>
void searchData(vector<string>& name, vector<int>& birthdate, vector<string>& address) {
bool found = false;
string entry;
string line;
int i = 0;
cout << "Please enter the name you want to search: " << endl;
getline(cin, entry);
std::ifstream in;
in.open("test_file.txt");
vector<T> file_data = getDataToVector(in);
while (!found) {
if (std::find(file_data.begin(), file_data.end(), entry) != file_data.end()) {
cout << "The name is found" << endl;
cout << file_data[i] << endl;
found = true;
}
i++;
}
}
template <class T>
vector<T> getDataToVector(std::ifstream infile) {
vector<T> data;
string line;
while (getline(infile, line)) {
data.push_back(line);
}
return data;
}
I am a beginner in c++ programming and am very appreciative for any help anyone can give me.