| | |
How to read a file using hash table
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi Guys,
Please help me in doing this.
I am trying to read a file using fstream, but my prof wants me to do the same using hash table, which i have know idea. Please tell me hw can i do the same.
The file contains huge data like the size of the block and its respective data.
Please find the code below.
Cheers
Please help me in doing this.
I am trying to read a file using fstream, but my prof wants me to do the same using hash table, which i have know idea. Please tell me hw can i do the same.
The file contains huge data like the size of the block and its respective data.
Please find the code below.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <fstream> #include <string> #include <algorithm> using namespace std; using std::ifstream; using std::ostream; using std::cout; int MAX_LENGTH = 0; int N = 1; class Entropy { public: void readData(); void process(); // void write(); ifstream fin; ofstream fout; }; int main() { Entropy zero_order; zero_order.readData(); } void Entropy::readData() { int n; char next; cout << "We are about to read the data from the trace.txt"; cout<<"\n\nHow many bits do you want to read?"; cin>>n; fin.open("trace.txt"); fout.open("dude.txt"); if(fin.fail()) { cout<<"Opening the input file failed\n"; exit(1); } fin.get(next); fout<<next; n--; while(n != 0) { fin.get(next); fout<<next; n--; } fin.close(); fout.close(); }
Cheers
Last edited by Ancient Dragon; Jul 7th, 2009 at 12:39 am. Reason: correct code tags
I don't see a hash table to read from... 
Create a hash function according to your needs and have a look at some standard hashing functions.Once you have a hashing function pass the key parameter of the data you want to write to hashing function and get the hash value corresponding to it.And you can open the file and move the filepointer to the location of your hash value and write the data there. Thats it. Later when you want to look for the data you just need to generate the hash value and corresponding position of data.
This ofcourse is only one among the several ways you can use a hashing.

Create a hash function according to your needs and have a look at some standard hashing functions.Once you have a hashing function pass the key parameter of the data you want to write to hashing function and get the hash value corresponding to it.And you can open the file and move the filepointer to the location of your hash value and write the data there. Thats it. Later when you want to look for the data you just need to generate the hash value and corresponding position of data.
This ofcourse is only one among the several ways you can use a hashing.
Last edited by csurfer; Jul 7th, 2009 at 12:44 am.
I Surf in "C"....
![]() |
Similar Threads
- Reading txt file into Hash Table (C++)
- Segmentation Fault Reading File Into Hash Table (C++)
- Help with finding a good use for a hash table in my program.... (C++)
- Conversion of CSV file to hash table (Perl)
- read a file (Perl)
- Pass XML file contents to a hash table. (Java)
- compile error-chained hash table c++ (C++)
Other Threads in the C++ Forum
- Previous Thread: Void Functions
- Next Thread: Having Function Problems...
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





