Reading an input file into arrays

For my assignment i need to read an input file into separate arrays.The input file has the id number of an object, the x-coordinate, the y-coordinate, and the radius. Input also has number at top for how many lines there are in the file. Input file looks like this

4
0 2 2 10
1 4 4 40
2 6 6 10
3 8 8 10

The numbers are all separated by one space.
So, I need to create arrays (id, x, y, & radius) and read in the corresponding numbers from the input file into these arrays (ex: idArray = {0, 1, 2, 3};) as well as stop reading into the arrays at the end of the input file,but I am unsure how to. Basically all I have done so far is open the files. Thanks for any help you can offer.


#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream phones;
ifstream towers;

phones.open("phones.txt");
if ( phones.fail() ) //check if open failed
{
cerr << "File phones.txt could not be opened";
return -1; //return an error code
}
towers.open("towers.txt");
if ( towers.fail() )
{
cerr << "File towers.txt could not be opened";
return -1;
}


return 0;
}
closed account (48T7M4Gy)
http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.