stringstream redfinition error

I'm using stringstream in order to change my string array into int. When I attempt to use it multiple times in the same function I get these errors:

error C2374: 'ss' : redefinition; multiple initialization
error C2088: '>>' : illegal for class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 else
		{
			defdiff = d10 - estats1.defense;
			stringstream ss(gear1.meleeweapons[0][4]);
			ss >> crit;
			//check for crit
			if (defdiff >= crit)
			{
				multiplyer = (defdiff / crit) + 1;
			}
			//convert weapon string into int d6 roll
			stringstream ss(gear1.meleeweapons[0][1]);
			ss >> dmgdice;
			//damage {apply crit here}
			for (int p = 1; p < dmgdice; p++)
			{
				d6 = (rand() % 6 + 1);
				cout << p << ") " << d6;
				dmgtotal = dmgtotal + d6;
			}
			
			cout << dmgdice << " d6 " << "x " << multiplyer << "= " << dmgtotal << endl;
			//adjust enemy hp
		}
On line 12 you are not using ss again, you are trying to create another variable with the same name, which is illegal as you have found out.

You can just make another stringstream.
Thank you.
You could also use the strringstream.str() member function to reassign the stream.

Topic archived. No new replies allowed.