Hi all my friends :)

I hope you're alright.. :)

first of all, I'm doing my assignment *don't worry I'll not ask to solve it :D*

I just got an error, don't know what's the solution for it
this is the error I'm getting:

C:\Documents and Settings\BoJaSoOM\Desktop\Data Structure\5\HashTable.cpp(200) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator

and the arrow for the error message pointing to [ while( fin >> n ) ]..

############## This is my code ################

#include <iostream>
#include <fstream>

using namespace std;

class Node
{
public:
	int data;
	int count;
	Node *link;

	Node()
	{
		data = count = 0;
		link = 0;

	}

	Node( int x )
	{
		data = x;
		count = 0;
		link = 0;

	}

}; // end class Node

class HashTable
{
private:
	Node *HT, *tmp;
	int tSize;

public:

	HashTable( int x )
	{
		HT = new Node[x];
		tSize = x;
		tmp = 0;

	} // end constructor for HashTable

	void insert( int x )
	{
		int loc;

		loc = x % tSize;
		
		if( HT[loc].count == 0 )
		{
			HT[loc].data = x;
			HT[loc].count++;

		}

		else
			if( x > HT[loc].data )
			{
				if(HT[loc].count == 1)
				{
					HT[loc].link = new Node(x);
					HT[loc].count++;
				}
				else if(HT[loc].link->data > x)
				{
					tmp = new Node(x);
					tmp->link = HT[loc].link;
					HT[loc].link = tmp;
					HT[loc].count++;
				}
				else
				{
					Node * tmp2;
					for(tmp = HT[loc].link, tmp2=tmp->link; tmp2; tmp2 = tmp, tmp = tmp->link)
						if(tmp2->data > x)
							break;
					Node *tmp3 = new Node(x);
					tmp3->link = tmp2;
					tmp->link = tmp3;
					HT[loc].count++;
				}
			}

				else
					if( x < HT[loc].data )
					{
						if(HT[loc].count == 1)
						{
							HT[loc].link = new Node(HT[loc].data);
							HT[loc].data = x;
							HT[loc].count++;
						}
						else
						{
							tmp = new Node(HT[loc].data);
							HT[loc].data = x;
							tmp->link = HT[loc].link;
							HT[loc].link = tmp;
							HT[loc].count++;
						}

					}

	} // end function insert

	bool search( int x, int &y )
	{
		y = x %tSize;
		if( HT[y]. data == x )
		{
			cout << "\nNumber found at location " << y << endl;
			return true;
		}
		else{
			for( tmp = HT[y].link; tmp; tmp = tmp ->link)
			{
				if(tmp->data == x)
				{
					cout << "\nNumber found at location " << y << endl;
					return true;
				}
			} // end for loop for searching an element entered by the user
		}
		cout << "\nNumber was not found\n";
		return false;

	} // end function search


	void print()
	{
		cout << "\nLocation			Entry(s)\n";
		cout << "=========			========\n";

		for( int i = 0; i < tSize; i++ )
		{
			cout << "HT [" << i << "]		" << HT[i].data;
			for( tmp = HT[i].link; tmp; tmp = tmp ->link)
			{
				cout << " -> " << tmp -> data;

			}

			cout << endl;

		} // end for loop

		int z = 0;
		int u;
		for( int j = 0; j < tSize; j++ )
		{
			if( HT[j].count > 0 )
			{
				z++;
			}

		}
		u = (z/tSize) * 100;
		cout << "\nThe utilization is " << u;
		cout << endl;
		cout << "The number of elements in the HashTable is ";

		int w = 0;

		for( int k = 0; k < tSize; k++ )
		{
			w+=HT[k].count;

		}

		cout << w;
		cout << endl;

	} // end print

};
	int main()
	{
		HashTable h( 1 );
		string n;
		int search;
		int x;

		// constructor opens the file
		ifstream fin( "dictionary.txt" );

		// If statement if the file can't be opened display message and exit the program
		if( !fin )
		{
			cerr << "Can't open the file..!!\n";
			exit(1);

		}

		while( fin >> n )
		{
			for( int i = 0; i < n.size(); i++ )
			{
				switch( n[i] )
				{
				case 'A':
				case 'B':
				case 'C':
				case 'D':
				case 'E':
				case 'F':
				case 'G':
				case 'H':
				case 'I':
				case 'J':
				case 'K':
				case 'L':
				case 'M':
				case 'N':
				case 'O':
				case 'P':
				case 'Q':
				case 'R':
				case 'S':
				case 'T':
				case 'U':
				case 'V':
				case 'W':
				case 'X':
				case 'Y':
				case 'Z':
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
					break;

				default:
					h.insert( n[i] );
					break;

				} // end switch

			} // end for loop

		} // end while loop

/*		cout << "\nSearching\n";
		cout << "========\n";
		cout << "Enter a number:\n";
		cin >> search;
		h.search( search, x );
		cout << "\n------------";
		cout << "\nEnter a number:\n";
		cin >> search;
		h.search( search, x );
		cout << "\n------------";
		cout << "\nEnter a number:\n";
		cin >> search;
		h.search( search, x );
		cout << "\n------------\n";

		h.print();*/


		cout << endl;

		return 0;
	}

Please Read this carefully, because I need your suggestion :) :
"I'm using HashTable to take words from a txt file called *dictionary.txt*, sounds good? nice.
Then Please read this part of the question:
(( The dictionary will consist of a list of words. You will need to insert them into a hash table. You may fix a size for your hash table . You may disregard any words in the dictionary which contain any characters which are not lowercase alphabetic characters (uppercase, punctuation, numbers). Use separate chaining to handle collisions. ))

Is what I'm doing in the code, using Switch loop, Is it right? or if not, then do you suggest any method??"


Please, I'm looking forward your ideas, and the corrections of my code..

Note: Everything is Appreciated :)


I'll be waiting.. :)

Thanks my friends in advance :)

>C2679: binary '>>' : no operator defined which takes
>a right-hand operand of type 'class std::basic_string
You forgot to include the <string> header.

commented: Thanks a lot :) +1

Opps Sorry.. going to try it :)

thanks a lot for reminding me :)

Anyway,, do you thing that the way I implemented the code is good?

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.