#include #include #include #include #include #include using namespace std; int main (int argc, char* argv[]) { /* Kontrollera att rätt mängd med argument har skickats in*/ if (argc != 2) { cerr << "Wrong input, input should be ./a.out " << endl; return 1; } /* Hämta filnamnet från kommandoraden och läs in filen */ ifstream ifs{argv[1]}; /* Läs in orden från filen till en lämplig behållare */ /* Ta bort ord som inleds med '#' tecken */ vector words{}; copy_if(istream_iterator(ifs), istream_iterator(), back_inserter(words), [](string const& word){ return word.front() != '#'; }); /* Vänd ordningen på orden backlänges */ vector fliped_words(words.size()); copy_backward(rbegin(words), rend(words), end(fliped_words)); // vector fliped_words{}; // copy(rbegin(words), rend(words), back_inserter(fliped_words)); // reverse(begin(words), end(words)); /* För varje ord vänd dessa bak och fram */ transform(begin(fliped_words), end(fliped_words), begin(fliped_words), [](string word) { reverse(begin(word), end(word)); return word; }); // transform(begin(fliped_words), end(fliped_words), begin(fliped_words), // [](string const& word) { // string tmp{}; // copy(begin(word), end(word), back_inserter(tmp)); // return tmp; // }); // transform(begin(fliped_words), end(fliped_words), begin(fliped_words), // [](string const& word) { // string tmp{word}; // copy_backward(rbegin(word), rend(word), end(tmp)); // return tmp; // }); /* Skriv ut orden i terminalen */ copy(begin(fliped_words), end(fliped_words), ostream_iterator(cout, " ")); cout << endl; }