Jun 28, 2010 at 5:58pm Jun 28, 2010 at 5:58pm UTC
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'
Jun 28, 2010 at 6:05pm Jun 28, 2010 at 6:05pm UTC
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.
Jun 29, 2010 at 12:49am Jun 29, 2010 at 12:49am UTC
thats the problem how do i convert string to number.....
Jun 29, 2010 at 2:44am Jun 29, 2010 at 2:44am UTC
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.....
Jun 29, 2010 at 7:45am Jun 29, 2010 at 7:45am UTC
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.