Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Overloading the ifstream operator >>

Posted on 1997-06-04
2
Medium Priority
?
950 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

610 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