954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Hashing from an Input File.

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[i] << num
in >> num;
}

return 0;
}

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

NICEGUY123
Newbie Poster
18 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

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

venkat arun
Light Poster
28 posts since Oct 2009
Reputation Points: 4
Solved Threads: 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


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?

NICEGUY123
Newbie Poster
18 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: