![]() |
Palindrome that will read a file
Hello
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> |
Re: Palindrome that will read a file
I don't know why you have used getline() under while test condition.
Code:
int main() |
Re: Palindrome that will read a file
Do I have to remove the getline() and replace it?
|
Re: Palindrome that will read a file
No, just think about where you want getline to get a line from. In this code:
Code:
getline(cin,inp); |
Re: Palindrome that will read a file
Now, I changed the getline(cin, inp) to getline(in, inp).
Code:
while(getline(in, inp)){When I remove the first "cout<<inp", only 5 of the input from file will be read, and all of them are "not palindromes". Example: some men interpret nine memos is not a palindrome a man a plan a canal - Panama is not a palindrome CSC121 is not a palindrome CSc121 is not a palindrome women understand men is not a palindrome When the second "cout<<inp" is removed, only the 4 last inputs are read, and still "not palindromes". Example: madam i'm adam is not a palindrome do geese see god? is not a palindrome never odd or even is not a palindrome murder for a jar of red rum is not a palindrome Any help on how to output the phrases from file all at once and how to ignore the spaces and punctuation marks? |
Re: Palindrome that will read a file
Okay... So I know now how to output the phrases all at once. This is what I did:
remove the "getline(in, inp)" and the 2nd "cout<<inp;" Code:
cout << inp; |
Re: Palindrome that will read a file
Just strip them out. Copy the letters to a new string, so the old string is "madam i'm adam" but the new string is "madamimadam".
|
| All times are GMT +5.5. The time now is 23:36. |