string conversion problem

Q:
input : 23/1/2010
output : January 23, 2010

#include <iostream>



using namespace std;

int main() {

string operation;
int a, c;
string b;
string op1, op2;


cout << "Enter the date: ";
getline(cin,operation);



int pos = operation.find('/');
string tmp = operation.substr(0,pos);
a = atoi(tmp.c_str());
operation = operation.substr(pos+1);


pos = operation.find('/');
op1 = operation.substr(0,pos);
operation = operation.substr(pos+1);



pos = operation.find('/');
tmp = operation.substr(0,pos);

operation = operation.substr(pos+1);


pos = operation.find('/');
op2 = operation.substr(0,pos);
operation = operation.substr(pos+1);



pos = operation.find('/');
tmp = operation.substr(0,pos);
c = atoi(tmp.c_str());
operation = operation.substr(pos+1);


if ( b == 1 ){
b = 1;
( cout << "January");
}



cout << "The date is " << b << " " << a << ", " << c << endl;


system("pause");
return 0;
}


ERROR: In function `int main()':
no match for 'operator==' in 'b == 1'
b is a string. It contains text. You can't compare it with a number. If the string contains a number in text form then you need to either convert the string to a number or the number to a string before you compare them.
thats the problem how do i convert string to number.....
can somebody help please if possible.....
the problem is
i assigned b as integer and there is some problem in if statement when i compile the program instead of output
"January" it is out putting some random integer numbers.....
Are you sure that b needs to be a string in the first place? a and c are both integers.

Also I don't think you ever give b a value before you test it.
Topic archived. No new replies allowed.