LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-31-2003, 06:17 AM   #1
petercool
Member
 
Registered: May 2002
Distribution: Mandrake 10.0
Posts: 78

Rep: Reputation: 15
Question C++ overloading extraction operator


C++ overloading extraction operator

What does line 9 do?

istream& operator >> (istream& str_in, struct data& d)
{
cout << "Enter Name : ";
str_in.getline(d.name,20);
cout << "Enter Age :";
str_in >> d.age;
cout << "Enter Height : ";
str_in >> d.height;
str_in.get(); // line 9
return(str_in);
}
 
Old 08-31-2003, 08:03 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote from "info iostream":
Code:
 - Method: istream& istream::get (streambuf& SB [, char DELIM])
     Read characters from the input stream and copy them on the
     `streambuf' object SB.  Copying ends either just before the next
     instance of the delimiter character DELIM (newline `\n' by
     default), or when either stream ends.   If DELIM was present in
     the input, it remains available as if unread.
 
Old 09-01-2003, 10:57 AM   #3
petercool
Member
 
Registered: May 2002
Distribution: Mandrake 10.0
Posts: 78

Original Poster
Rep: Reputation: 15
Sorry but I don't quite understand that.
 
Old 09-01-2003, 02:20 PM   #4
devoyage
Member
 
Registered: Aug 2003
Distribution: many
Posts: 37

Rep: Reputation: 15
the delimiter '\n' is still in the input stream. that last get() will take it out so that it doesn't screw with your program later.

ex, if you had this later:
Code:
char input;
cout << "Please enter a character: ";
cin.get(input);
the program would just whiz by, placing a '\n' (or whatever the delimiter was) into "input".

EDIT:

Hko, how did you get the iostream (and I'm guessing STL) documentation in the info system? I can't find it there?

Thanks

Last edited by devoyage; 09-01-2003 at 02:22 PM.
 
Old 09-02-2003, 10:11 AM   #5
petercool
Member
 
Registered: May 2002
Distribution: Mandrake 10.0
Posts: 78

Original Poster
Rep: Reputation: 15
Thanks I think I understand now
 
Old 09-06-2003, 06:35 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by devoyage
Hko, how did you get the iostream (and I'm guessing STL) documentation in the info system? I can't find it there?
On my (debian sarge) system, this command gets me there:

info -f iostream-295

If this doesn't work, try CTRL-s or just s to search for "ios..."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Operator Overloading problem ashwinipahuja Programming 1 06-23-2004 05:59 AM
c++ [] operator overloading exodist Programming 12 04-17-2004 03:06 PM
C# with dotGNU, operator overloading exodist Programming 2 03-15-2004 05:52 PM
Builtin operator overloading. exodist Programming 15 03-11-2004 10:41 PM
c++ overloading input operator true_atlantis Programming 4 02-25-2004 07:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration