Click to See Complete Forum and Search --> : problem compiling C++ with stringstream


gamblor01
06-14-2005, 11:57 AM
Can anyone offer some advice why the following code won't compile? I have an unsigned int array (a) and I'm trying to take a[1], and convert it to a string using std::stringstream. Here's just a code snippet:


a[1] = convertToUnsInt(input) + convertToUnsInt(revInput);
/* now put the integer value in a[1] back into char* input */
std::stringstream myStream;
myStream << a[1];
myStream >> input;


Everytime I compile however, I get an error on the line "std::stringstream myStream" that says the following:

error: aggregate `std::stringstream myStream' has incomplete type and cannot be defined


WHAT?!?!?! What on earth does that mean? I'm a Java head, so I'm used to using Integer.parseInt() to do my conversions for me, and then making an integer a string is as easy as concatenating!...

String myStr = "" + someInt;


Not so easy in C++. I would use atoi but it returns an int, and I may be dealing with a value that's too large for int (they're unsigned values) so I had to write my own function to convert that DOES return an unsigned int. Now I can't get that int back to a string.

tecknophreak
06-14-2005, 02:37 PM
#include <sstream>

Should do it. That error message let's you know that you forgot the header.

gamblor01
06-14-2005, 07:18 PM
Wow that was easy...I feel stupid. Thanks.

tecknophreak
06-16-2005, 08:08 AM
No problem, most complier errors are ones that make you feel stupid, especially the missing a bracket one. Man I hate that one... :mad:

XiaoKJ
06-16-2005, 12:31 PM
I esp hate missing a semi-colon.

Good thing I code little.