How to scan a string?

Hello. My task is to programm a infix to postix programm.
I already created a stack with a linked list. Now I need to scan a string and for example if somebody enters "a+b*2" ... I need to scan the string for example ... "if string == + push to stack" How I can do that? Please give me a hint. Here is my code!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;


template< class T>
class Stack {

private:
   int MAX;
   int top;
   T* items;

public:
	Stack(int size){
		MAX = size;
		top = -1;
		items = new T[MAX];
	}

	~Stack(){ delete [] items; }

	void push(T c){
		if(full())
        {
			cout << "Stack Full!" << endl;
			exit(1);
		}

		items[++top] = c;
	}

	T pop(){
		if(empty()){
			cout << "Stack Empty!" << endl;
			exit(1);
		}

		return items[top--];
	}

	int empty(){ return top == -1; }

	int full(){ return top+1 == MAX; }
};

int main(){

	Stack<char> st(10);

        //the letters 'A' - 'J'
	    //for(int i = 65; i < 75; i++)
		//st.push(i);

        //remove all the data
	    //for(int j = 0; j < 10; j++)
		//cout << st.pop() << endl;
		string str;
		 string::iterator it;
		cout << "Please enter the infix value" << endl;
		cin >> str;
         //Infix to Postfix
		 for ( it=str.begin() ; it < str.end(); it++ )
		 {
             if (it==t) //Don´´ work why?
             {
             cout << "Test" << endl;
             }
         }
		
    getchar();
    system("pause");
	return 0;
}
I'm not sure what you mean by line 65 "it==t". I understand this is where your error is, but I'm reading through your code and not seeing a variable t.

By the sound of your introductory paragraph you're trying to compare character values, correct? If that's the case, then you'll need something like

if (str.substr(it,1).compare("insert value here?")==0)

Since this actually looks at the input string and compares it to a one-length string (instead of comparing numbers), I think this is what you were looking for. Then again I could be completely wrong.
Topic archived. No new replies allowed.