That depends, I would say, on how you mean to use the two methods. Personally, I would probably have only one form of the method, one which takes an istream&
as it's argument; this covers both the case of a file input (ifstream&
) and string input (istringstream&
), and gives you additional options besides (e.g., reading from std::cin
for a filter).
I would add that you may want to have it return a vector
of an abstract Token
class, rather than of plain std::string
s. This would allow you to specialize the set of tokens a given Lexical
object returns with additional information aside from the contents of the string itself.
Or perhaps you could combine the two sets of ideas, and have it return a stream of Token
s? You'd need to define a tokenstream
class, as an extended form of an ios
, and then... hmmn, let me think this out a bit.