How to use this ifstream?

I have a constructor which takes in a reference variable of type ifstream. I want to be able to define a file which to get one line of text from and then use the created ifstream to read that one line in the constructor. Something like this:

1
2
3
4
int main(){
	ifstream myStream(FILENAME);
	PegBoard newGame(myStream);
}

In my constructor I want to read that one line:
1
2
3
4
PegBoard::PegBoard(ifstream & sin){
// How would I read that one line in this constructor?

}
Last edited on
You read into it the same way as any ifstream; >>, getline() etc. Am I misunderstanding your question?
Well, how would I do that?
Here is one way to read into an ifstream:
1
2
string str;
getline(sin, str); // gets one line from sin and puts it into str 
Thanks so much. I can't believe I didn't figure that out. I feel like I tried that but I guess not. Thanks.
Topic archived. No new replies allowed.