By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

overloaded >> and istream delimiters

P: n/a
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 }?
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Todd Beauchemin" <ma*********@hotmail.com> 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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.