Annoying habit to put these line numbers there to make it non-copyable.
>
> The problem here is that the scanner considers that
> "word" and "word,word" are two different words.
>
> Apparently just searches the first non blank character.
You want to specify more delimiters in istream than white space?
> How can we change the >> operator to call a user defined function to
> scan the characters?
>
> My C++ knowledge doesn't go that far.
To my knowledge you must imbue stream with suitably for your taste
screwed up locale.
#include <locale>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <sstream>
class Delims
: public std::ctype<char>
{
mask t_[table_size];
public:
explicit Delims(size_t refs = 0)
: std::ctype<char>(&t_[0], false, refs)
{
std::copy_n(classic_table(), table_size, t_);
t_['-'] = (mask)space;
t_['\''] = (mask)space;
t_[','] = (mask)space;
}
};
int main() {
std::istringstream input("Subway,McDonald's and Burger-King.");
std::locale x(std::locale::classic(), new Delims); // that new
// doesn't leak
input.imbue(x);
std::copy(std::istream_iterator<std::string>(input),
std::istream_iterator<std::string>(),
std::ostream_iterator<std::string>(std::cout, "\n")
);
}
Who uses the C++ streams for anything but for training students to think?