istringstream

Can anyone please tell me why I cannot reassign a value into values?

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
int _tmain(int argc, _TCHAR* argv[])
{
	rectangle r;

	std::istringstream values;

	float rectVal = 0.0f;
	std::string input;

	std::cout << "Enter the values of the rectangle:\nx value: ";
	std::getline( std::cin, input, '\n' );
	values.str( input );
	values >> rectVal;
	r.setX( rectVal );

	std::cout << "\ny value: ";
	std::getline( std::cin, input, '\n' );
	values.str( input );
	values >> rectVal;
	r.setY( rectVal );

	std::cout << "X: " << r.getX() << " " << "Y: " << r.getY() << '\n';
	std::cout << "\n\nThe area is: " << r.area2D() << '\n';

	return 0;
}


The only way I seem to be able to get around this, is by creating more streams:

Line 5:
std::istringstream Xvalues, Yvalues;


Lines 12 & 13:
1
2
Xvalues.str( input );
Xvalues >> rectVal;


Lines 18 & 19:
1
2
Yvalues.str( input );
Yvalues >> rectVal;



Thanks for any help.
That sounds familiar, I think I've ran into this. Have you tried calling values.clear() before values.str( input )? I'm guessing there might be some leftover flags interfering.
Yeah, that works! Thanks for the reply, much appreciated.
Topic archived. No new replies allowed.