Hi,

I would like a good reference for reading arrays from text files. The program i need to write requires that we read a text file that has the information in an array format.

thanks

Its pretty simple, really. Just create an array and read each line into its own element of the array. You will need a loop to read the file until eof() and an int counter to keep track of the line number read so that it will know which row to use in the array.

There are a couple ways to implement this: and here is probably the easiest (and best) approach.
Since this is c++ thread then use <vector> as the array and <string> to hold the text of each line. Create a std::ifstream to open the file and call getline() to read each line.

Look through the C++ Code Snippets and you will probably find example programs that read files into arrays.

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.