multiplication problem

I am working on an assignment for a class but for some reason * does not work. I keep getting an error saying "error C2676: binary '*' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator"

Can anyone help me figure this out? Here is my code I am using Visual Studio 2012.

#include <iostream>
#include <string>

using namespace std;

int main(){
string value;
double propertyTax = .6;
float assessment;
assessment = value * propertyTax;

cout << "What is the property value?" << endl;
getline(cin, value);
cout << "The assessment value for land worth $" << value << " is $" << assessment << endl;

getchar();
return 0;
}
Thats because you cannot do that with a string type(the lvalue)
a string is a literal value of text:

"Hello. I enjoy ribs and beer."
"So do I"
"How old are you?"
"23"

These are all strings, including the last one.

to use value as an actual number, you would need to change the type identifier to a number, like int or double or float.

so,

instead of
string value;

it would be:
float value = 0.0f;
(Please use double and not float, unless you have a good reason.) And what exactly should a string times a double be?

1
2
3
4
??? operator*(const string &s, double x) {
    ...
    return ???
}
Last edited on
Topic archived. No new replies allowed.