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

  • Home
  • SEARCH
  • 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 8580313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:48:08+00:00 2026-06-11T20:48:08+00:00

I’m attempting to read from a file a customer’s name, id, and loan information.

  • 0

I’m attempting to read from a file a customer’s name, id, and loan information. The file is setup like this:

Williams, Bill
567382910
380.86
Davidson, Chad
435435435
400.00

Basically, every time I come to a new name, the information is going to be placed into a new object of the Customer class. My problem is, I’m trying to read from the file but I’m not sure how to overload the operator correctly to read only 3 lines from the file like I want to and put them in the right place.

I create the customer and open the file here:

Menu::Menu()
{
Customer C;
ifstream myFile;

myFile.open("customer.txt");
while (myFile.good())
{
  myFile >> C;
  custList.insertList(C);
}
}

This is just what I have in my .cpp file for a Menu class. Here is my code (the tiny bit that I know how to do) for the overloaded operator in my .cpp file for the Customer class.

istream& operator >> (istream& is, const Customer& cust)
{


}

I’m not sure how to only get the three lines and place them into their respective places inside of a Customer which are:

string name
string id
float loanamount

If anyone could help me out with this I’d really appreciate it.

  • 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-11T20:48:09+00:00Added an answer on June 11, 2026 at 8:48 pm

    Something like:

    istream& operator >> (istream& is, Customer& cust) // Do not make customer const, you want to write to it!
    {
        std::getline(is, cust.name); // getline from <string>
        is >> cust.id;
        is >> cust.loanAmount;
        is.ignore(1024, '\n'); // after reading the loanAmount, skip the trailing '\n'
        return is;
    }
    

    And here’s a working sample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.