getline() on a fstream which is passed as an argument in a class constructor
Hi I have some trouble with using getline() in a my class. My class name
is myStringList, stringList is a list< string> member variable, and below
is the constructor.
input is an fstream object created in main(), open() a file and is passed
into the constructor as an argument.
myStringList::myStringList(std::fstream& input)
{
std::string temp;
while (std::getline(input,temp))//will temp be cleared?
{
myStringList::stringList.push_back(temp);
}
}
The getline() cannot work in this way. It seems because input is a
reference to fstream, i think? If I were to pass in argv[1] as the
argument and create a fstream object in this constructor itself, getline
will work.
What should be the correct syntax to use getline() on a fstream which is
passed as an argument in a class constructor?
No comments:
Post a Comment