How to get multiple inputs from a single line?

int main ()
{
Calculator calc;
char c;
double x,y;
cin >> x;
cin.ignore('+'||'-'||'*'||'/'));

cin >> y;
calc.add(x,y);
cout << calc.answer;
return 0;
}

I'm trying to make a calculator that could compute for the answer in a single line input but I dont know how to get the char of the operand. anyhelp?
1
2
3
4
int a = 0, b = 0;
char op = 0;

cin >> a >> op >> b;
OR :
1
2
3
4
double a = 0, b = 0;
char op;

cin >> a >> op >> b;

This should work for all numbers and all cases.
cin >> a >> op >> b; does not guarantee that the input is from a single line.
@JLBorges
How do you mean?


1
+
2
a = 1	op = +	b = 2

1+
2
a = 1	op = +	b = 2

1+2
a = 1	op = +	b = 2
Only the third example is input from a single line. (The first two involve input from more than one line.)
@JLBorges
The OP will always and always try to pick the third one. That is perfectly valid.
Why does the OP have to input more than more line, can you explain?
Topic archived. No new replies allowed.