Hello,
I have an assignment where I have to create a hash table and load 30 part numbers into it- should be a 2-d array...and eventually I have to prompt the user to choose an algorithm and keep track of collisions. But I am starting really small with this and want to start with reading a text file into the array. I am close (i think :confused: ), but I think I may have put the values into my txt file incorrectly. Can anyone offer advice. I will show my code also
the text file just has the numbers 101-110, 301-310 & 501-510 in a list.
//read part numbers from txt file 'parts.txt'
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
int array[41];
for(i=0; i<5; i++) //clear array
array[i] = 0;
ifstream in("part.txt", ios::in | ios::binary);
if(!in){
cout << "cannot open file.\n";
return 1;
}
in.read((char *) &array, sizeof array); //read block of data
for(i=0; i<5; i++) //show values read from file
cout << array[i] << " ";
in.close();
return 0;
}