Hello,
I need to write from a file to an array. The data in the file is stored as two numbers separated by spaces (tabs). I am having trouble populating the array, but receive no errors so I'm not sure what the deal is. For pieces of the code will Thanks in advance!
If you know the size of the file, then it will be easy. Just set the size of the array to the number of positions you need for all of the numbers in the file.
then:
1 2 3 4 5 6 7 8 9 10
int SIZE = ?; // Whatever size you need for your array
int myArray[SIZE]; // Creating array
int i = 0; // Initialize iterator
string line;
while(getline(fileName, line) // Getting lines as strings
{
myArray[i]=stoi(line); // Putting 'line' into array after string to integer conversion
i++;
}