So i have
Class Parser and in this class is constructor
Parser(string s){ // constructor
tokens = s.c_str(); // convert to a C string
opStack.push(END); // initialize opStack
}
tokens was defined as const char *tokens in private ;
That is in the parser.h file
However when i try to cout tokens in an implemented method in parser.cpp..it prints out garbage...and weird looking symbols. If i cout tokens in the constructor..it prints out the string..which is what its supposed to do..So how is it that when i move outside the constructor, it changes?
My main goes like this..
cout << "Enter expression: ";
cin.get(line, 100);
cin.ignore(100, '\n');
str = string(line); //convert line to a string
if (str == "quit") break;
Parser par(str); // new parser
par.toPostfix();
As you can see the constuctor for par is called...I can cout tokens correctly if i put it in the constructor..However once i put it in toPostfix() it prints out weird looking symbols.