I need help in understanding how input file in C++ works. Here is what i need to do. I need to be able to open a input file called input.txt. That file will contain 15 numbers in a list format.
6
.34
74
34
12
31
23
.
.
.
First number will be the size of the hash the second would be a number to multiply by and then a list of numbers as keys, and finally the last number to be a number to search for using different hashing functions. Fist off i need help understanding how i can store the numbers seperatly so i can access for their use in other places in the program. I was thinking about placing all the numbers into an array. like below. Then accessing the number in the locations that corresponds to its place in the array. Let me know if you think that it might work this way or if there is a better way to do this.

ifstream in;
ofstream out;
int num;
in.open("input.txt");
in.open("output.txt");


int i = 0
in >> num;

while ( num )
{
a << num
in >> num;
}

return 0;
}

p = a[0];
Alpha = a[1];

Maybe you can get the first two numbers(the ones that specify the size and multiply value) using the

getline ()

function. After that you can get the other numbers using the same function, and start placing them in the table

Maybe you can get the first two numbers(the ones that specify the size and multiply value) using the

getline ()

function. After that you can get the other numbers using the same function, and start placing them in the table

So it would be something like
int p
p = getline(in 1) //where 1 is the line number of the file??

int alpha

alpha = getline(in 2)


Then how do i store the rest into the array or will i have to do a
getline() for all the lines to use them in my hash?

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.