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 7512085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:45:27+00:00 2026-05-29T23:45:27+00:00

I have written a program that stores booking information in a text file in

  • 0

I have written a program that stores booking information in a text file in c++. So far I can search the booking number and check if that number exists in the text file and print “Record is found”.

Now when I try to print the line in which the booking information is stored , the program always prints the last line in the text file.

for example it says that “Record 123 is found” but it prints the record “999” which is the last in the txt file.

Can you help me solve this problem by showing me some codes , about how I can print a specific line from a file.

My code is like this :

if ((i = search.find(x)) != search.end()) 
{ 
    cout << id << name << phone number << credit card number<<...endl;
} 

this code allways prints the last line.

  • 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-05-29T23:45:29+00:00Added an answer on May 29, 2026 at 11:45 pm

    Without seeing your code, we are left to guess blindly, and typically we don’t have the patience for that (no offense, it’s just that typically our guesses are wrong).

    That said, I’ve got a hunch that what you are doing is using locals to read in your data and store them in some sort of structure (I’m guessing a std::map) and then when you search for the data you are finding it, but making the mistake of using the locals instead of the iterator.

    You should be using your iterator (which you label x in your example) to output the data. For example, if search is a std::map, then the data for the value is stored in the second part of the std::pair returned from find():

    auto x = search.find(x);
    
    // this assumes your map's value is a struct with name, id, etc for fields.
    if (x != search.end())
    {
        std::cout << "Found: " << x->second.name << '\t' 
            << x->second.id << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program that will etablish a network connection with a remote
I have written a program that uses qhttp to get a webpage. This works
I have written a java program that is actually works as a gui to
I have written a c# program that calls a c++ dll that echoes the
Below I have written a sample program that I have written to learn about
I have written an ActionScript client program that tries to connect to a local
I have a PHP program that has been written keeping in mind a single
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I have a website cgi-bin program that is written in c++. Unfortunately the website
I have a console program written in C# that I am using to send

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.