passing a file object as a const reference

Aug 9, 2011 at 6:31am
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
Aug 9, 2011 at 7:35am
i am not changing fin inside the function. just reading the file.

Sounds contradictory...
Aug 9, 2011 at 7:48am
What Syuf means is that in order to read the file, you need to modify the std::fstream object. No way around it.
Aug 9, 2011 at 8:36am
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 ??
Aug 9, 2011 at 9:18am
While reading you change the get pointer position.
Topic archived. No new replies allowed.