C++ : Closing specific ifstreams in a global vector with just the file name

  c++, filereader, ifstream, vector

For this project I have to open a file with an ifstream in one function. The code i have written can be seen below:

bool FileReader::openFile(std::string fileName) {

std::ifstream inFile;
streams.push_back(std::move(inFile));

if (streams.back().is_open()) {
    std::cout << "File Found";
    return true;
}
else {
    std::cout << "File Not Found";
    return false;
}

and then close it in another function. Here is that empty function:

bool FileReader::closeFile(std::string fileName) {

return false;
}

Both of these functions work by passing in the file path as a parameter and the ifstreams are stored in a global vector so multiple files can be open at once

What I dont understand is how i can close one of those streams with just the filename as a paramater.

Any help would be greatly appreciated

Source: Windows Questions C++

LEAVE A COMMENT