passing an ifstream argument to a function

hi,
I want to open a file within a function, so I passed the function an ifstream parameter and the relevant code is:
1
2
3
4
5
6
7
8
string test(ifstream& in , vector<string>)
{
  vector<string> line;
string work;
  while(getline(in,line))
    {...}
return work;
}

within the main function, I have the following code:
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
  string mtest;
vector<string> mstr;
  string pfile="f2.txt";
    ifstream infile;
    infile.open(pfile.c_str());
   
mtest=test(infile,mstr);

return 0;
}

but upon execution, it waits for a cin entry, rather than opening the file and getting the lines from there.
can you please help me fix it...thx!
That doesn't compile. getline(in,line) is trying to read a vector.
so how do I write it correctly so that it reads the lines(i.e. string vector) from the infile which is an ifstream object.
Topic archived. No new replies allowed.