太经典的题目了,最经在学习stl,给出stl的一种实现方法
/*
* main.cpp
*
* Created on: 2011-7-20
* Author: tyj
*/
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
int main() {
string sentence = "Something in the way she moves";
vector<string> tokens;
istringstream iss(sentence);
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter<vector<string> >(tokens));
copy(tokens.rbegin(), tokens.rend(), ostream_iterator<string>(cout, " "));
}