Is there simpler way?

Viewed 363

I'd like to know if there is a shorter / simpler way to:

  1. Split the incoming string by words
  2. Write the tokens in reverse order to stdout

There are two restrictions: no libraries and no loops

#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <deque>

void list_string_elements(std::string s) {
    using namespace std;

    istringstream iss (s);
    deque<string> v;

    copy(istream_iterator<string>(iss), istream_iterator<string>(), front_inserter(v));

    copy(v.begin(),v.end(),ostream_iterator<string>(cout,"\n"));
}
3 Answers
Related