Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: C++ issue with file I/O  (Read 3088 times)

0 Members and 1 Guest are viewing this topic.

Khasiar

    Topic Starter


    Intermediate

    C++ issue with file I/O
    « on: October 20, 2008, 04:16:02 AM »
    Hey guys,

    I cant seem to figure out how to make a single input file be read and output into another file when its in an array for example

    ID     Type         Name    Stock   Price
    21     Phone     Nokia     10     $500     
    22     Laptop    IBM        10     $2000
    etc    etc           etc         etc    etc

    when i try to read this from the input file it will only outputs the 21 in the first line and everything after the space is left out, i tried doing this a different way but i thought it was a really dumb way to fix the issue, this is what ive done:

                    string itemID;
       string itemType;
       string itemName;
       string itemStock;
       string itemPrice;

       ifstream ID;
       ifstream Type;
       ifstream Name;
       ifstream Stock;
       ifstream Price;

       ofstream outData;
       

       ID.open("ID.txt");
       Type.open("Type.txt");
       Name.open("Name.txt");
       Stock.open("Stock.txt");
       Price.open("Price.txt");
       outData.open("outData.out", ios::app);
     
       ID >> itemID;
       Type >> itemType;
       Name >> itemName;
       Stock >> itemStock;
       Price >> itemPrice;

       outData << "\t\t\t::Inventory:: \n\n\n" << itemID << endl << itemType  << endl << itemName << endl
       << itemStock << endl << itemPrice << endl;

    along with me having to make a bunch of unneccessary files i also have to seperate my data, also my files output horizontally not vertically, so basically i need to know how to input an array, although it if was that basic i would know how to do it :s

    any help will be great

    Khasiar
    « Last Edit: October 20, 2008, 04:33:39 AM by Khasiar »

    Khasiar

      Topic Starter


      Intermediate

      Re: C++ issue with file I/O
      « Reply #1 on: October 23, 2008, 04:19:15 AM »
      dw guyz i figured it out, in case you wanted to know

      ID >> itemID >> itemType >> itemName >> itemStock >> itemPrice;

      outData << itemID << " " << itemType  << " " << itemName << " "
      << itemStock << " " << itemPrice << endl;

      is the way to get the space included from input