overloaded >> and istream delimiters

T

Todd Beauchemin

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 }?
 
V

Victor Bazarov

Todd Beauchemin said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top