your function getfile returns an ifstream but in your code you never set anything equal to that return value. To illustrate what I'm talking about...
you did
getfile(infile);
what I suggest you should have done is something along the lines of
infile = getfile(infile);
The diference is that the return value of getfile is stored somewhere, whereas the way you did it the return value is just dropped.
Zhuge brings up a good point that you should really be passing your ifstream by reference.
What your posted code is doing is taking in an ifstream called words, making a copy of it, making some changes to that copy and finally returning the changed version of words.
If you change your function to pass by reference with a void return value it will take in the actual ifstream and make changes directly to it so that when your function has finished the changes will have been made.
pass by value with a return value
1 2 3
|
ifstream getfile(ifstream words){
...
return;}
|
pass by reference with no return value
1 2 3
|
void getfile(ifstream& words){
...
}
|
This is a concept beginner c++ programmers have a really hard time wrapping their head around.
Read this:
http://www.tech-recipes.com/rx/1232/c-pointers-pass-by-value-pass-by-reference/
I was once you! Keep on Givin' 'er!