file input


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: file input

  1. #1
    Bob Welch Guest

    file input


    The input to the program is a series of data sets, one per line, with each
    set representing data. Each data set conisists of a name, followed by a comma
    and one or more spaces, a float number, one or more spaces, and an int number.
    It looks like this:
    Orville's Acres, 114.8 43801
    Jolly Good Plantation, 183.2 104570

    Thanks;
    Bob Welch


  2. #2
    cary Guest

    Re: file input


    "Bob Welch" <rjwelch@coollink.net> wrote:
    >
    >The input to the program is a series of data sets, one per line, with each
    >set representing data. Each data set conisists of a name, followed by a

    comma
    >and one or more spaces, a float number, one or more spaces, and an int number.
    > It looks like this:
    >Orville's Acres, 114.8 43801
    >Jolly Good Plantation, 183.2 104570
    >
    >Thanks;
    >Bob Welch
    >


    Declare a file stream object, then i a string, a float
    and an int to input your data from the file to your program. You
    will need to put this into a loop that reads until EOF to read
    in all of your data:

    #include <fstream.h>

    ifstream inFile;
    inFile.open ("Data");
    string name;
    float floatNum;
    int intNum;

    while (inFile)
    {
    inFile >> name >> floatNum >> intNum;

    }

    (This will read the comma into the name string.)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center