List inventory file to screen

This is a discussion on List inventory file to screen within the C++ Programming forums, part of the General Programming Boards category; Lets say I have 10 items on my inventory list, I dont want to write this out Code: inData >> ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    73

    List inventory file to screen

    Lets say I have 10 items on my inventory list, I dont want to write this out
    Code:
    inData >> prod >> item >> price >> tax;
    cout << prod << "  " << item << "  " << price << "  " << tax << endl;
    outData << prod << "  " << item << "  " << price << "  " << tax << endl;
    10 times, is there a way to write that out with a ++ sign that once I set something to 10 it knows to print that out 10 times vs. having to oput that statement in 10 times? I want to make it look nice vs. alot of garbage that does not need to be in there.

    Bryan

  2. #2
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    what about putting it in a loop?
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    this is my file and I need to get rid of 5 sets of lines...I have 6 sets of lines for 6 products in my Inventory.txt file but I need it to make a loop so I only have to put one set of instructions vs 6 sets for 6 items? Does this make sense?

    Bryan
    Attached Files Attached Files

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Code:
    int itemNum = 10;
    
    for (int count = 0; count < itemNum; count++)
    {
         ....
       codes to print data go here
    }
    The codes inside the loop will be executed "itemNum" times.
    You could use while loop also, instead.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I was leaving out the count part...thanks alot

    Bryan

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I am creating a .H File to store my Array of Inventory Items...I need to be able to reference back to that for the prices and to see if it is taxable or not. How can I design something in my main .cpp file to know how to loko for the prie of that certain product?

    Bryan

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    As a general rule the .h or .H extension is reserved for header files that contain declarations of functions or classes/structs. To store data in file generated by one run of a program and used in another run of a program at a later time use a file extension like .txt or .dat or some other choice. Use file streams (or file pointers if you prefer C style file handling) to write data to and read data from the given file. You can't use data in the file directly, you need to download it from the file memory to RAM memory you program is using.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ordered linked list
    By redmondtab in forum C Programming
    Replies: 48
    Last Post: 10-22-2006, 07:09 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21