Thread: ifstream problem

  1. #1
    Registered User
    Join Date
    Jan 2009

    ifstream problem

    I have written a program to write a file and save as txtfile. i have then written another to read said txt file. I can display this file no problem.

    i now have to be able to read specific lines from this txt file so that i can create an order but i am really having no joy. do i need to copy the file into my existing program in order to take information from it?
    the txt file is basically a menu with a list of itemno product and prices. i need to be able to create and order of say itemno 3, and a qty of 2 but the prodram needs to be able to read the file to see what itemno 3 is and how much it costs.

    i have written the code for the no and qty but it is not reading the file forwhat it is and the cost. How do i go about doing that?

    any hints would be great thanks

  2. #2
    Registered User
    Join Date
    Jan 2005
    Unless you are writing fixed-length records (which is doubtful given your description) then you'll have to read the entire file into your program, or at least until you find the information you're looking for.

    If there isn't too much data, I might read the whole thing in to data structures first and then just query the data structures. But that decision depends on a bunch of other factors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list problem
    By kzar in forum C Programming
    Replies: 8
    Last Post: 02-05-2005, 04:16 PM
  2. small reference problem
    By DavidP in forum C++ Programming
    Replies: 6
    Last Post: 06-21-2004, 07:29 PM
  3. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  4. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM