overloaded >> and istream delimiters

Discussion in 'C++' started by Todd Beauchemin, Jul 31, 2003.

  1. OK. I want to overload the >> operator so I can do
    cin >> myset.

    I have the format of set input be {ele1, ele2}.

    Any suggestions on how to do this. I have
    the following:
    template<class T, class A, class L>
    std::istream& operator>> (std::istream& i, std::set<T, A, L>& s) {
    T val;
    if (i.get () == '{') {
    i >> val;
    s.insert (val);
    while (i.get () == ',') {
    i >> val;
    s.insert (val);
    }
    } // if
    return i;
    } // >> for set

    but if i do {google, yahoo} for input then the set becomes
    google,

    is there anyway to adjust the delimiters such that it wont pick up
    the , or the }?
    Todd Beauchemin, Jul 31, 2003
    #1
    1. Advertising

  2. "Todd Beauchemin" <> wrote...
    > OK. I want to overload the >> operator so I can do
    > cin >> myset.
    >
    > I have the format of set input be {ele1, ele2}.
    >
    > Any suggestions on how to do this. I have
    > the following:
    > template<class T, class A, class L>
    > std::istream& operator>> (std::istream& i, std::set<T, A, L>& s) {
    > T val;
    > if (i.get () == '{') {
    > i >> val;
    > s.insert (val);
    > while (i.get () == ',') {
    > i >> val;
    > s.insert (val);
    > }
    > } // if
    > return i;
    > } // >> for set
    >
    > but if i do {google, yahoo} for input then the set becomes
    > google,
    >
    > is there anyway to adjust the delimiters such that it wont pick up
    > the , or the }?


    I recommend to read the entire line between { and } and then parse it.

    Victor
    Victor Bazarov, Jul 31, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    18
    Views:
    552
  2. Marco Trapanese

    strtok_r and delimiters

    Marco Trapanese, May 20, 2008, in forum: C Programming
    Replies:
    4
    Views:
    958
    Marco Trapanese
    May 20, 2008
  3. dmitrey
    Replies:
    4
    Views:
    457
  4. xmllmx
    Replies:
    5
    Views:
    587
    Jorgen Grahn
    Jun 15, 2010
  5. Albert Schlef

    String#split and capturing delimiters

    Albert Schlef, Oct 30, 2009, in forum: Ruby
    Replies:
    3
    Views:
    181
    Rajinder Yadav
    Oct 30, 2009
Loading...

Share This Page