i am working on the output from the stack and list but i got 2 errors and i dont know how to fix it, hope some1 can help me to figure it out
thank you
header.h
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Lexeme
{
private:
string Lex;
string type;
public:
Lexeme();
string getLex ();
string gettype ();
void setLex (string);
void settype (string);
};
#include "TheHeader.h"
#include <stack>
#include <list>
void ReadFile();
template <typename T>
T StringToNumber ( const string &Text)
{
stringstream ss(Text);
T result;
return ss >> result ? result : 0;
}
int main ()
{
ReadFile();
return 0;
}
void ReadFile()
{
char a;
string str = "";
Lexeme temp;
stack <Lexeme> name;
list <Lexeme> listD;
int size;
ifstream file ("sample.txt",ios::in);
if(!file)
{
cout<<"Unable to open the file!!!" <<endl;
exit(1);
}
file >> a;
while (file)
{
if (a == '/' ||a == '*' ||a == '+' ||a == '-' ||a == ';' ||a == '^'||a == '='||a == '('||a == ')')
{
cout << a << " symbol" << endl ;
str = a;
temp.setLex(str);
temp.settype("SYMBOL");
listD.push_back(temp);
name.push(temp);
file >> a;
}
else { str = a;file >> a;
while( a >= '0' && a <= '9' || a == '.')
{
str.append(1,a);
file >> a;
}
temp.setLex(str);
temp.settype("NUMBER");
listD.push_back(temp);
name.push(temp);
cout << str << " number" <<endl ;
str = "";
}
}
cout << " from the list: " << endl;
list <Lexeme>::iterator place;
for(place = listD.begin(); place != listD.end(); ++place)
{
cout<<*place<<" "<<endl;
size = name.size();
}
cout << " stack: "<< endl;
for (int i=0; i < size; i++)
{
cout<<name.top()<<" ";
name.pop();
}
file.close();
}
header.cpp
#include "TheHeader.h"
Lexeme::Lexeme()
{
Lex = "";
type ="";
}
string Lexeme::getLex ()
{
return Lex;
}
string Lexeme::gettype ()
{
return type;
}
void Lexeme::setLex(string b)
{
Lex = b;
}
void Lexeme::settype (string c)
{
type = c;
}
and the error i got is:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Lexeme' (or there is no acceptable conversion)
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Lexeme' (or there is no acceptable conversion)