input stream problem

Hi, im reading B.Stroustrup's book : Programming principles and practice using C++ . Im doing every single exercise and so far i have done them all.
But now i saw this exercise and i dont really know where to begin

Modify the ... program to make the input stream an explicit parameter. rather than simply using cin. Also give Token_stream constructor an istream& parameter so that when we figure out how to make our own streams (attached to files) we can use the ... program for those. Hint : Dont try to copy an istream


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>

class Point{
public:
	int x;
	int y;
	Point() : x(0), y(0) {}
};

class Token_stream{
	Point point;
	// ...
public:
	Point get_input();
	// ...
};

Point Token_stream::get_input(){
	std::cout << "Enter 2 ints ";
	std::cin >> point.x >> point.y;
	return point;
}

int main(){

	Token_stream ts;
	Point p;
	p=  ts.get_input();
	std::cout << "x = " << p.x << std::endl
	          << "y = " << p.y << std::endl;
}


Please help
Last edited on
Hints:
Add a member of type std::istream reference to Token_stream
Write a constructor that takes an istream reference
Initialise member in constructor
In get_input(), use member instead of std::cin
Thanks man a lot :)
Topic archived. No new replies allowed.