Subtracting Strings ('str' not found in scope)
Jan 14, 2012 at 7:15pm UTC
I keep running into a problem with trying to subtract strings from one another.I keep getting an error saying that:
error: 'str' was not declared in this scope
I know it has something to do with <string> only being in the std namespace. Any ideas on how to fix this?
Class Definition and whatnot
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 <fstream>
#include <cstdlib>
#include <string>
using namespace std;
class City
{
public :
City();
City operator +(const City& city1);
City operator -(const City& city1);
friend istream& operator >>(istream &stream, City &c1);
friend ostream& operator <<(ostream &stream, City &metro);
private :
string name;
int pop;
int area;
double ratio;
};
int choose_function();
Here's where the problem keeps coming up
1 2 3 4 5 6 7 8 9 10 11 12 13 14
City City::operator -(const City& city1)
{
City metro;
string tmp;
tmp = str.find(city1.name);
metro.name = str.erase(tmp);
metro.pop = pop - city1.pop;
metro.area = area - city1.area;
return (metro);
}
Jan 14, 2012 at 7:46pm UTC
The problem is you using a variable str (on lines 6 and 7, second snippet) that has not been declared anywhere. That's what's written in the error message... I assume you wanted name instead ?
Jan 17, 2012 at 3:19am UTC
your area should be a double, just so you know...also, hurry up! due soon
Topic archived. No new replies allowed.