Making one string out of another?

I am looking to remove punctuation and spaces from a string and I thought I could do this by checking with isalnum()and inserting alphanumeric bits into a new string using stringstreams.

My function:

bool palindrome (string input)
int len = input.length();
bool isPalindrome = true;
for (int a = 0, b = len - 1; a <= len, b >= 0; a++, b--)
char forward = input[a];
char backward = input[b];
if (isalnum(forward) && isalnum(backward)) // remove spaces and punctuation
stringstream ss;
string finalInput;
ss << forward << backward;
finalInput += ss.str;
char newForward = finalInput[a];
char newBackward = finalInput[b];
if (newForward != newBackward)
isPalindrome = false;
return isPalindrome;

I am getting the error line:

"no match for operator+= in finalInput += ss.str"

I am wondering why this is happening and how I can fix it, or is using a string stream just the wrong thing to do?

Thank you!
Last edited on
You forgot specify parentheses. Write

finalInput += ss.str();

instead of

finalInput += ss.str;
Topic archived. No new replies allowed.