// Bjarne Stroustrup 1/17/2010 // Chapter 11 Exercise 9 /* Write a function vector split(const string& s) that returns a vector of whitespace-separated substrings from the argument s. */ #include "std_lib_facilities.h" /* Here, first, is the obvious split(): */ vector split(const string& s) // return a vector of copies of words in s { istringstream is(s); vector vs; string buf; while (is>>buf) vs.push_back(buf); return vs; } /* This split() is easy to implement and trivial to use (see the test below), but we do copy strings a lot and we get back *copies* of the words. An alternative design returns a vecor of indices into the string: */ vector spliti(const string& s) // return a vector of indices of words in s { vector res; bool in_word = false; for (int i = 0; i ln1 = split(line); cout << "words in line:\n"; for (int i=0; i ln2 = spliti(line); cout << "words in line:\n"; for (int i=0; i