Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:35:28+00:00 2026-06-14T05:35:28+00:00

Possible Duplicate: Manipulate Input File Stream C++ How to overload cin to read file

  • 0

Possible Duplicate:
Manipulate Input File Stream

C++ How to overload cin to read file

I was trying the following with operator overload..

struct myself
{
string myname;
}

istream &operator>> (istream &stream, myself &mm)
{
cout << "Enter my name:";
stream >> mm.myname;
return stream;
}

int main()
{
myself mm;
cin >> mm;

cout << mm.myname;

}

and its work, able to echo out what i actually type.

Now i trying to proceed with

cout << "Enter file name to read: ";

//assume user type myfile.txt

cin >> readFile;

How do i overload my cin to make it read file.

Consider my file is something like

sometextdocument.txt that contains data like

Map2D, [3, 2]
Dot3D, [25, -69, -33], [-2, -41, 58]
Map3D, [6, 9, -50]
Map2D, [3, 2]
Dot3D, [7, -12, 3], [9, 13, 68]
Map3D, [6, 9, 5]
Map2D, [3, 2]
Dot3D, [70, -120, -3], [-29, 1, 268]
Dot3D, [7, 12, 3], [-9, 13, 68]
Map3D, [1, 3, 8]
Dot2D, [5, 7], [3, 8]

And then i wanna cout << "Number of records read: " << number << endl;
then do a return stream, how do i overload it to work as cin read a file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:35:30+00:00Added an answer on June 14, 2026 at 5:35 am

    Try like this: hope it will be helpful

    istream &operator>> (istream &in, char* fname){ 
      inFile.open(fname);
      char ch1;
      while (inFile.get(ch1)) {
           cout<<ch1;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Parsing XML String in C# How to process the below XML file
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Circular definition in C typedef struct{ node *next; node *last; } doubleLink;
Possible Duplicate: How can I lock a file using java (if possible) I have
Is it possible to manipulate or duplicate the building data ( landscape.man_made ) for
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: Large Numbers in Java I need to take and manipulate an integer
Possible Duplicate: Cyclic module dependencies and relative imports in Python Consider the following example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.