the first line tells how many data points are there ...and then we have the x-coordinate and y-coordinate and a character c or v
i have to read this data strip out the number of lines (i.e is the first line......lines 30) from the text file and store it in a structure and make array out of the structure.

Flip ahead in your book (I assume that you're using one or have one as a reference) to iostream. I'll give you a basic idea of what to look for, mainly because I work much more in C instead of C++ and because I never could see much use of streams -- but using them here will be the easier option for you.

Declare a file stream (of type ifstream if I recall correctly) and call its open method. Then use the input operator, >>, to read in each value. After you've read the line for the number of records, then it should look something like this:

Code:

typedef struct
{
double x;
double y;
char t;
} try;
try try_record;
ifstream ifile;
// open ifile and read the first line to get the record count
// for each record
ifile >> try_record.x;
ifile >> try_record.y;
ifile >> try_record.t;
// now process that record; e.g. store it in an array

There are a lot of details that I'm leaving out plus I could be making some mistakes here (remember, I don't normally use this), so be sure to review the material in your book.

The thing that makes this easier for you is that ifstream will treat the spaces and newline as delimiters separating the values being read, so you don't have to deal with them explicitly.

Though I have to agree with e4c5 that the best language for text processing is perl. However, I've found some cases where I had a lot more control over the program with C. Everything's a trade-off.

Perl may be a great language for text processing, but it's power is overkill here. This is a trivial program in C or C++. I have every confidence that our student will be able to handle his homework without resorting to perl.

Originally posted by ClayDowling Perl may be a great language for text processing, but it's power is overkill here. This is a trivial program in C or C++. I have every confidence that our student will be able to handle his homework without resorting to perl.

Ah, but wouldn't that be a great red herring?

He should know now what he needs to do. It's still up to him to figure out how to do it and how to make it work.