Clearing a stringstream

Hello, everybody. I'm trying to solve some problems over at Project Euler, but I got stuck. The problem reads as follow:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.



So, what I thought is that I need to convert integers into strings in order to compare the numbers. I tried it like this:

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
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	int a = 100;
	int b = 100;
	int producto;
	string numero;
	stringstream convertir;

	while (a < 1000)
	{
		for (;b < 1000; b++)
		{
			producto = a*b;
			convertir << producto;
			numero = convertir.str();
			cout << numero << endl;
		}
		a++;
		b = 100;
	}

	return 0;
}


but apparently -- convertir << producto -- appends the next data right besides the one that was already there. After three cycles, convertir holds this value:

100001010010200

What I would like to do is to empty this stringstream in order to analyze each result separately.

Any tips?
Thanks a lot!

I had used convertir.str() = "" , but now I see the difference. I still have a hard time reading the references, mainly because I don't have a full grasp on the terminology yet.
Topic archived. No new replies allowed.