ok so I just stiched from c to c++ and im having problems using strings for some of my functions. this is my code
Code:
#include <iostream>
using namespace std;
int main() {
string item;
while (cin >> item) {
cout << item << endl;
}
return 0;
}
say i enter this info to it (in one line then press enter):
1 2 3 4 5 + - display 12 *
I get this
Code:
1 2 3 4 5 + - display 12 * delete
1
2
3
4
5
+
-
display
12
*
delete
now this is the part where im not understanding how to put it in code. Our teacher wants us do an add numbers to a stack and add or subtract some numbers is when enter the signs (+ -). I cant think of a way to do it. I just need help thinking not asking for you guys to do my homework just some enlightenment.
thank you for reading.
for like the one that is enter here how would I do this function to add a one(1) to the stack? how can it differentiate from letters and numbers?
can I do some thing like this?
Code:
while (cin >> item) {
if (item == int){
add number one to stack;
}
if (item== "delete" ignoring capitalization)
delete all the items from stack
}
}
}