C++ print palindromes from a text file -
check if string palindrome using link above try solve problem (among many others, ive been trying solve various ways day no dice, first c++). other examples in array format, , can't make assumptions length of word. i'm trying make program detect if word palindrome or not. have text file 1 word per line, , want test each word, line line, if palindrome, , if print screen, , if not, ignore , not print it. figured best way locate palindromes reverse word line line , match original, , if same (==), print it. here have far:
#include <iostream> #include <vector> #include <string> #include <cctype> #include <fstream> using namespace std; int main(int argc, char *argv[]) { std::string line; std::ifstream infile("wordlist.txt"); } string reverse(string line){ if (line == string(line.rbegin(), line.rend())) { cout << string; } }
all appreciated
i guess question homework question , information on how complete c++ coding.
you not know how read file contents in c++. here's link of how it:
read file-contents string in c++
i not sure answered. if question homework question, here's info of how ask:
https://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions
Comments
Post a Comment