istream parameter question

For a class project, my professor wanted us to use

extern Token getToken(istream *br, string& lexeme);


The getToken() function is implemented in another cpp file, and used in a main file. When i try to give it an ifstream, or cin as a parameter, i get an error. I don't have much experience with I/O, but isn't istream supposed to recognize both if and iostreams? I saw other examples online and it has the istream parameter as a reference, but the professor doesn't want us changing the header file.
Show the actual code, it's hard for someone to help you without seeing how you're calling the function. My guess is that you're not passing the address of cin, would be be passed as "&cin" and not just cin.
Last edited on
Instead of

Token getToken(istream *br, string& lexeme);

consider

Token getToken(istream &br, string& lexeme);
@LB His professor is probably trying to get them to see the difference between pointers and references, he said the professor didn't want them editing the header.
That being said, I agree it's pointless to use pointers here when references are more syntactically clean and safer. Weird way of teaching.
Last edited on
Ah, I missed that the header could not be changed. In that case, you just need to take the address of std::cin.
Topic archived. No new replies allowed.