I need help on my palindrome code. My palindrome uses stacks and queues. The input must be read from a file. However, my code will run but there is something wrong with it. The program does read the .txt file but it will not get the input from the .txt file and I still need to type an input. Here's my code:
Code:
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <fstream>
using namespace std;
void is_palindrome (string);
bool operator==(const stack<char>&, const queue<char>&);
bool operator!=(const stack<char>&, const queue<char>&);
int main(){
string inp;
int i;
ifstream in("input.txt");
if (!in){
cout << "Cannot Display Text." << endl;
}
while(getline(in, inp)){
stack<char> *s;
queue<char> *q;
s = new stack<char>;
q = new queue<char>;
cout << "Input"<<inp;
getline(cin,inp);
string::iterator i;
for (i = inp.begin(); i != inp.end(); i++) {
s->push(*i);
q->push(*i);
}
cout << inp << " is ";
if (*s != *q) {
cout << "not ";
}
cout << "a palindrome." << endl;
delete s;
delete q;
}
return 0;
}
bool operator==(const stack<char> &s1, const queue<char> &q1) {
bool eq = true;
stack<char> s = s1;
queue<char> q = q1;
if (s.size() == q.size()) {
while ((s.empty() == false) && (eq == true)) {
eq = (s.top() == q.front());
s.pop();
q.pop();
}
} else {
eq = false;
}
return eq;
}
bool operator!=(const stack<char> &s, const queue<char> &q) {
return !(s == q);
}

