passing a file object as a const reference

hello

void compress::makeDict( ifstream &fin)
{
string word;
while(fin){
fin>>word;
cout<<word<<endl;
}
}

In the above function if fin is taken as constant reference (const ifstream &fin), it is throwing an error even though i am not changing fin inside the function. just reading the file.

error: no match for 'operator>>' in 'fin >> word
i am not changing fin inside the function. just reading the file.

Sounds contradictory...
What Syuf means is that in order to read the file, you need to modify the std::fstream object. No way around it.
hello syuf and helios, thanks of your reply.

can you please explain a bit more "in order to read the file, you need to modify the std::fstream object" ??? how it gets modified ??
While reading you change the get pointer position.
Topic archived. No new replies allowed.