Assume the class
myClass
is already implemented.
That doesn't help, we can't just assume it's implemented and know what its interface is or how to use it, so we can't answer your question.
Why do you expect std::ifstream
to know how to work with myClass
? Why are you passing inputFile
as an argument to a member function of inputFile
? Have you looked at any documentation or examples showing how to use getline
?
Assuming you can construct a myClass
from a std::string
this will work (note it reads into a string
and note you don't need to close the file manually):
vector<myClass> read_file(string filename)
{
ifstream inputFile(filename);
if (!inputFile.is_open())
throw runtime_error("File Not Found!");
vector<myClass> myVec;
string line;
while (getline(inputFile, line))
{
myClass m(line);
myVec.push_back(m);
}
return myVec;
}