I have a text file i want to read data from the first line of the test file is ow many lines are in it then on each line seperated by a space is itemnumber itemprice itemquantity.

3
39284 5.75 12
18372 4.50 23
27649 12.99 81

how would i read in the file and store the item numbers in one array, item prices in another, and item quantity in a thrid array?

Recommended Answers

All 2 Replies

Open std::ifstream for input

int item_numnber[3];
float item_prices[3];
int item_qry[3];

In a loop, use ifstream's >> operator to read each field into it's array element.

This would be better in a class. Then use an array of your class type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.