473,411 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

overloaded >> and istream delimiters

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
1 3541
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jaime Ashander | last post by:
Hello, I've overloaded the istream operator >> to output the private data members of my class Word, i'm using the operator go get data from an input file with something like //--snip-- #include...
3
by: glen stark | last post by:
Hi all. I'm working with an array of member function pointers (they are all get function of the class Bead). The typedef is: typedef _real (Bead::*_beadGfp)(void); I have a class System...
4
by: Ook | last post by:
I'm a but fuzzy about this. You would call it like this:Polynomial poly; // Polynomial is my class with various properties cin >> poly; In the function itself, I would, for example, do the...
5
by: jalkadir | last post by:
I my program I have overloaded the inserters and extractor operator. ---name.hpp friend std::ostream& std::operator<<( std::ostream& os, const jme::Name& obj ); friend std::istream&...
4
by: Don Hedgpeth | last post by:
Here's a question - I'm new to c++ and I have two classes that overload the >> operator. One class calls the other...such as. //code for class1 friend std::istream& operator >> (std::istream&...
11
by: icanoop | last post by:
I would like to do this MyClass x; istringstream("XXX") >> x; // Works in VC++ but not GCC instead of MyClass x; istringstream iss("XXX"); iss >> x; // Works in both GCC and VC++
13
by: Randy | last post by:
Is there any way to do this? I've tried tellg() followed by seekg(), inserting the stream buffer to an ostringstream (ala os << is.rdbuf()), read(), and having no luck. The problem is, all of...
11
by: Ashwin | last post by:
hi guys, i have overloaded >operator for my own string class .the function is as given below istream& operator>>(istream &in,string1 &s) { char *a; a=new char; in>>a; s=a;
2
by: B. Williams | last post by:
I have an assignment for school to Overload the operators << and >and I have written the code, but I have a problem with the insertion string function. I can't get it to recognize the second of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.