hey guys!
i'm a newbie in programming specifically text files.
i kinda need some help with this problem that i'm trying to solve
about text files. I'M NOT REALLY ASKING FOR A COMPLETE CODES.
problem:
i have a text file, let's call it "vocab.text", the text file contains
alphabetical words only.
then i have to create a program that reads the text file and
finds the longest word that has its REVERSE word.
example, i found the word "desserts" and its reversal word which is
"stressed", the 2 words should be the longest words,
the program should output both "desserts" & "stressed".
take note that both reversal words are in the text file "vocab.text",
the programs' job is only to find the longest reversed words like "desserts" & "stressed".
ANY ADVICE WOULD BE GREAT!
THANKS IN ADVANCE!
so far i have this code:
Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string str, longest; ifstream textfile ("vocab.txt"); if (textfile.is_open()) { while (!textfile.eof()) { getline (textfile,str); reverse (str.begin(), str.end()); if (str.size () > longest.size ()) longest = str; } cout << longest <<endl; textfile.close(); } else cout << "Unable to open file"<<endl; system ("pause"); return 0; }



LinkBack URL
About LinkBacks




