How to use stringstream to output a polynomial?

Basically, I have three variables a, b and c, such that ax^2+bx+c = 0, and I have to print out the polynomial correctly (a b and c can all be either negative or zero). I'm not sure how to start on this, though - any hints would be appreciated
This is quite simple, do you know how to output stuff normally using a stringstream?
not really, and the cplusplus.com reference page is rather confusing to me
It works exactly like using cout, except the data is put into a stringstream instead of shown on the console.

e.g.:
1
2
3
std::stringstream str;
str<<"1"<<23<<"/"<<"x";
std::cout<<str.str(); //this gets the string version of what you put in 


This outputs:
123/x
What would be the best way to take into account terms that are zero or negative? Should I use if/else statements or switching statements?
I would use if/else. Switch might work but wouldn't be any better IMO.
Almost done, but one last error: (this is done as part of implementing a function)

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
string Polynomial::str()
{
	std::stringstream str1;
	std::stringstream str2;
	std::stringstream str3;

	std::stringstream stra;
	std::stringstream strb;
	std::stringstream strc;

	stra << a;
	strb << b;
	strc << c;

	if (a == 0)
		str1;
	else;
	{
		str1 << stra << "x^2 ";
	}

	second:
	if (b == 0)
		str2;
	else;
	if (b > 0)
	{
		str2 << "+ " << strb <<"x ";
	}
	else;
	if (b < 0)
	{
		str2 << "- " << strb << "x ";
	}
	
	third:
	if (c == 0)
		str3;
	else;
	if (c > 0)
		str3 << "+ " << strc;
	else;
	if (c < 0)
		str3 << "- " << strc;

	return (str1 << str2 << str3);
}


I'm getting a error from the very last line:

"error: conversion from 'std::basic_ostream<char, std::char_traits<char> >' to non-scalar type 'std::string' requested"
Call the .str() operator before you return it. You are returning a string, not a stringstream.
Topic archived. No new replies allowed.