?
Solved

Overloading the ifstream operator >>

Posted on 1997-06-04
2
Medium Priority
?
949 Views
Last Modified: 2006-11-17
I am writing a program and am attempting to overload the ifstream operator >>. I have done it in this form:

ifstream & operator >> (ifstream & infield, Class_name & cclass)

where i pass a class type as the second parameter.
However, for what I am doing this time, I only need to pass it a string but I have a friend who has had trouble with this before while trying to pass a pointer. Will it work in either of these ways:

ifstream & operator >> (ifstream & infield, string & instring)

or

ifstream & operator>>(ifstream & infield, string instring).

If neither of these will work, please tell me the correct syntax for passing it a string instead of a class as the second parameter.

Thank you.
Orpheus
0
Comment
Question by:orpheus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
strobert earned 200 total points
ID: 1163837
the first one:
ifstream & operator >> (ifstream & infield, string & instring)

string is a class, but even with a base type like int, just have the second arg be a ref to the type you want to instream.
0
 

Author Comment

by:orpheus
ID: 1163838
thanks, ill give it a try.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question